Add soft level errors distinction for SendGrid service
[MAILPOET-1154]
This commit is contained in:
@ -13,10 +13,15 @@ class SendGridMapper {
|
|||||||
$response['errors'][0] :
|
$response['errors'][0] :
|
||||||
sprintf(__('%s has returned an unknown error.', 'mailpoet'), Mailer::METHOD_SENDGRID);
|
sprintf(__('%s has returned an unknown error.', 'mailpoet'), Mailer::METHOD_SENDGRID);
|
||||||
|
|
||||||
|
$level = MailerError::LEVEL_HARD;
|
||||||
|
if(strpos($response, 'Invalid email address') === 0) {
|
||||||
|
$level = MailerError::LEVEL_SOFT;
|
||||||
|
}
|
||||||
|
|
||||||
$subscriber_errors = [];
|
$subscriber_errors = [];
|
||||||
if(empty($extra_params['test_email'])) {
|
if(empty($extra_params['test_email'])) {
|
||||||
$subscriber_errors[] = new SubscriberError($subscriber, null);
|
$subscriber_errors[] = new SubscriberError($subscriber, null);
|
||||||
}
|
}
|
||||||
return new MailerError(MailerError::OPERATION_SEND, MailerError::LEVEL_HARD, $response, null, $subscriber_errors);
|
return new MailerError(MailerError::OPERATION_SEND, $level, $response, null, $subscriber_errors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
namespace MailPoet\Test\Mailer\Methods\ErrorMappers;
|
||||||
|
|
||||||
|
use MailPoet\Mailer\MailerError;
|
||||||
|
use MailPoet\Mailer\Methods\ErrorMappers\SendGridMapper;
|
||||||
|
|
||||||
|
class SendGridMapperTest extends \MailPoetTest {
|
||||||
|
|
||||||
|
/** @var SendGridMapper*/
|
||||||
|
private $mapper;
|
||||||
|
|
||||||
|
/** @var array */
|
||||||
|
private $response = [];
|
||||||
|
|
||||||
|
function _before() {
|
||||||
|
$this->mapper = new SendGridMapper();
|
||||||
|
$this->response = [
|
||||||
|
'errors' => [
|
||||||
|
'Some message',
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
function testGetProperError() {
|
||||||
|
$error = $this->mapper->getErrorFromResponse($this->response, 'john@rambo.com', []);
|
||||||
|
expect($error->getLevel())->equals(MailerError::LEVEL_HARD);
|
||||||
|
expect($error->getMessage())->equals('Some message');
|
||||||
|
expect($error->getSubscriberErrors()[0]->getEmail())->equals('john@rambo.com');
|
||||||
|
}
|
||||||
|
|
||||||
|
function testGetSoftErrorForInvalidEmail() {
|
||||||
|
$this->response['errors'][0] = 'Invalid email address ,,@';
|
||||||
|
$error = $this->mapper->getErrorFromResponse($this->response, ',,@', []);
|
||||||
|
expect($error->getLevel())->equals(MailerError::LEVEL_SOFT);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user