diff --git a/mailpoet/lib/Mailer/Methods/ErrorMappers/MailPoetMapper.php b/mailpoet/lib/Mailer/Methods/ErrorMappers/MailPoetMapper.php index daeabc4f5f..f6b3f82ce1 100644 --- a/mailpoet/lib/Mailer/Methods/ErrorMappers/MailPoetMapper.php +++ b/mailpoet/lib/Mailer/Methods/ErrorMappers/MailPoetMapper.php @@ -86,7 +86,10 @@ class MailPoetMapper { $message .= ' ' . $e->getMessage(); } break; + case API::RESPONSE_CODE_INTERNAL_SERVER_ERROR: + case API::RESPONSE_CODE_BAD_GATEWAY: case API::RESPONSE_CODE_TEMPORARY_UNAVAILABLE: + case API::RESPONSE_CODE_GATEWAY_TIMEOUT: $message = __('Email service is temporarily not available, please try again in a few minutes.', 'mailpoet'); $retryInterval = self::TEMPORARY_UNAVAILABLE_RETRY_INTERVAL; break; diff --git a/mailpoet/lib/Services/Bridge/API.php b/mailpoet/lib/Services/Bridge/API.php index 79cea318dd..c00a38ad78 100644 --- a/mailpoet/lib/Services/Bridge/API.php +++ b/mailpoet/lib/Services/Bridge/API.php @@ -15,7 +15,10 @@ class API { const RESPONSE_CODE_KEY_INVALID = 401; const RESPONSE_CODE_STATS_SAVED = 204; + const RESPONSE_CODE_INTERNAL_SERVER_ERROR = 500; + const RESPONSE_CODE_BAD_GATEWAY = 502; const RESPONSE_CODE_TEMPORARY_UNAVAILABLE = 503; + const RESPONSE_CODE_GATEWAY_TIMEOUT = 504; const RESPONSE_CODE_NOT_ARRAY = 422; const RESPONSE_CODE_PAYLOAD_TOO_BIG = 413; const RESPONSE_CODE_PAYLOAD_ERROR = 400; diff --git a/mailpoet/tests/unit/Mailer/Methods/ErrorMappers/MailPoetMapperTest.php b/mailpoet/tests/unit/Mailer/Methods/ErrorMappers/MailPoetMapperTest.php index fb17cd5ee6..9e3498c693 100644 --- a/mailpoet/tests/unit/Mailer/Methods/ErrorMappers/MailPoetMapperTest.php +++ b/mailpoet/tests/unit/Mailer/Methods/ErrorMappers/MailPoetMapperTest.php @@ -184,4 +184,19 @@ class MailPoetMapperTest extends \MailPoetUnitTest { expect($error->getMessage())->stringContainsString("You’ll soon be able to send once our team reviews your account."); } + + public function testGetUnavailableServiceError() { + $apiResult = [ + 'code' => API::RESPONSE_CODE_GATEWAY_TIMEOUT, + 'status' => API::SENDING_STATUS_SEND_ERROR, + 'message' => 'Service is temporary unavailable', + ]; + + $error = $this->mapper->getErrorForResult($apiResult, $this->subscribers); + expect($error)->isInstanceOf(MailerError::class); + expect($error->getRetryInterval())->equals(MailPoetMapper::TEMPORARY_UNAVAILABLE_RETRY_INTERVAL); + expect($error->getOperation())->equals(MailerError::OPERATION_SEND); + expect($error->getLevel())->equals(MailerError::LEVEL_HARD); + expect($error->getMessage())->equals('Email service is temporarily not available, please try again in a few minutes.'); + } }