Make key check error messages more descriptive [MAILPOET-990]
This commit is contained in:
committed by
pavel-mailpoet
parent
3499de05e8
commit
91ff008485
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,43 @@ class ServicesTest extends MailPoetTest {
|
||||
);
|
||||
$response = $this->services_endpoint->checkMSSKey($this->data);
|
||||
expect($response->status)->equals(APIResponse::STATUS_NOT_FOUND);
|
||||
expect($response->errors[0]['message'])->contains((string)Bridge::CHECK_ERROR_UNAVAILABLE);
|
||||
expect($response->errors[0]['message'])->contains(
|
||||
$this->invokeMethod(
|
||||
$this->services_endpoint, 'getErrorDescriptionByCode', array(Bridge::CHECK_ERROR_UNAVAILABLE)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function testItRespondsWithErrorIfServiceDidNotReturnAResponseCodeDuringMSSCheck() {
|
||||
$this->services_endpoint->bridge = Stub::make(
|
||||
new Bridge(),
|
||||
array(
|
||||
'checkMSSKey' => null,
|
||||
'storeMSSKeyAndState' => Stub::once()
|
||||
),
|
||||
$this
|
||||
);
|
||||
$response = $this->services_endpoint->checkMSSKey($this->data);
|
||||
expect($response->status)->equals(APIResponse::STATUS_NOT_FOUND);
|
||||
expect($response->errors[0]['message'])->contains(
|
||||
$this->invokeMethod(
|
||||
$this->services_endpoint, 'getErrorDescriptionByCode', array(Bridge::CHECK_ERROR_UNKNOWN)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function testItPrintsErrorCodeIfServiceReturnedAnUnexpectedResponseCodeDuringMSSCheck() {
|
||||
$this->services_endpoint->bridge = Stub::make(
|
||||
new Bridge(),
|
||||
array(
|
||||
'checkMSSKey' => array('code' => 404),
|
||||
'storeMSSKeyAndState' => Stub::once()
|
||||
),
|
||||
$this
|
||||
);
|
||||
$response = $this->services_endpoint->checkMSSKey($this->data);
|
||||
expect($response->status)->equals(APIResponse::STATUS_NOT_FOUND);
|
||||
expect($response->errors[0]['message'])->contains('404');
|
||||
}
|
||||
|
||||
function testItRespondsWithErrorIfMSSCheckThrowsAnException() {
|
||||
@ -171,7 +207,43 @@ class ServicesTest extends MailPoetTest {
|
||||
);
|
||||
$response = $this->services_endpoint->checkPremiumKey($this->data);
|
||||
expect($response->status)->equals(APIResponse::STATUS_NOT_FOUND);
|
||||
expect($response->errors[0]['message'])->contains((string)Bridge::CHECK_ERROR_UNAVAILABLE);
|
||||
expect($response->errors[0]['message'])->contains(
|
||||
$this->invokeMethod(
|
||||
$this->services_endpoint, 'getErrorDescriptionByCode', array(Bridge::CHECK_ERROR_UNAVAILABLE)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function testItRespondsWithErrorIfServiceDidNotReturnAResponseCodeDuringPremiumCheck() {
|
||||
$this->services_endpoint->bridge = Stub::make(
|
||||
new Bridge(),
|
||||
array(
|
||||
'checkPremiumKey' => null,
|
||||
'storePremiumKeyAndState' => Stub::once()
|
||||
),
|
||||
$this
|
||||
);
|
||||
$response = $this->services_endpoint->checkPremiumKey($this->data);
|
||||
expect($response->status)->equals(APIResponse::STATUS_NOT_FOUND);
|
||||
expect($response->errors[0]['message'])->contains(
|
||||
$this->invokeMethod(
|
||||
$this->services_endpoint, 'getErrorDescriptionByCode', array(Bridge::CHECK_ERROR_UNKNOWN)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function testItPrintsErrorCodeIfServiceReturnedAnUnexpectedResponseCodeDuringPremiumCheck() {
|
||||
$this->services_endpoint->bridge = Stub::make(
|
||||
new Bridge(),
|
||||
array(
|
||||
'checkPremiumKey' => array('code' => 404),
|
||||
'storePremiumKeyAndState' => Stub::once()
|
||||
),
|
||||
$this
|
||||
);
|
||||
$response = $this->services_endpoint->checkPremiumKey($this->data);
|
||||
expect($response->status)->equals(APIResponse::STATUS_NOT_FOUND);
|
||||
expect($response->errors[0]['message'])->contains('404');
|
||||
}
|
||||
|
||||
function testItRespondsWithErrorIfPremiumCheckThrowsAnException() {
|
||||
|
Reference in New Issue
Block a user