Add subscriber errors passing via MailerError object

We want to process errors for individual subscribers.
Subscriber errors were inlined into error message string.
This commit changes this so that we are now able to get
subscriber errors as a data which are easy to process further.

[MAILPOET-1154]
This commit is contained in:
Rostislav Wolny
2018-09-05 13:11:59 +02:00
parent 0923c892c1
commit 223c2e1562
12 changed files with 197 additions and 57 deletions

View File

@ -3,6 +3,7 @@ namespace MailPoet\Mailer\Methods\ErrorMappers;
use MailPoet\Mailer\MailerError;
use MailPoet\Mailer\Mailer;
use MailPoet\Mailer\SubscriberError;
class SendGridMapper {
use ConnectionErrorMapperTrait;
@ -11,9 +12,11 @@ class SendGridMapper {
$response = (!empty($response['errors'][0])) ?
$response['errors'][0] :
sprintf(__('%s has returned an unknown error.', 'mailpoet'), Mailer::METHOD_SENDGRID);
$subscriber_errors = [];
if(empty($extra_params['test_email'])) {
$response .= sprintf(' %s: %s', __('Unprocessed subscriber', 'mailpoet'), $subscriber);
$subscriber_errors[] = new SubscriberError($subscriber, null);
}
return new MailerError(MailerError::OPERATION_SEND, MailerError::LEVEL_HARD, $response);
return new MailerError(MailerError::OPERATION_SEND, MailerError::LEVEL_HARD, $response, null, $subscriber_errors);
}
}