Make key check error messages more descriptive [MAILPOET-990]

This commit is contained in:
stoletniy
2017-07-07 12:44:38 +03:00
committed by pavel-mailpoet
parent 3499de05e8
commit 91ff008485
2 changed files with 94 additions and 6 deletions

View File

@ -60,8 +60,8 @@ class Services extends APIEndpoint {
default:
$code = !empty($result['code']) ? $result['code'] : Bridge::CHECK_ERROR_UNKNOWN;
$error = sprintf(
__('Error validating MailPoet Sending Service key, please try again later (code: %s)', 'mailpoet'),
$code
__('Error validating MailPoet Sending Service key, please try again later (%s)', 'mailpoet'),
$this->getErrorDescriptionByCode($code)
);
break;
}
@ -116,12 +116,28 @@ class Services extends APIEndpoint {
default:
$code = !empty($result['code']) ? $result['code'] : Bridge::CHECK_ERROR_UNKNOWN;
$error = sprintf(
__('Error validating Premium key, please try again later (code: %s)', 'mailpoet'),
$code
__('Error validating Premium key, please try again later (%s)', 'mailpoet'),
$this->getErrorDescriptionByCode($code)
);
break;
}
return $this->errorResponse(array(APIError::BAD_REQUEST => $error));
}
private function getErrorDescriptionByCode($code) {
switch($code) {
case Bridge::CHECK_ERROR_UNAVAILABLE:
$text = __('Service unavailable', 'mailpoet');
break;
case Bridge::CHECK_ERROR_UNKNOWN:
$text = __('Contact your hosting support to check the connection between your host and https://bridge.mailpoet.com', 'mailpoet');
break;
default:
$text = sprintf(_x('code: %s', 'Error code (inside parentheses)', 'mailpoet'), $code);
break;
}
return $text;
}
}