Refactor sending methods to use error mappers
We want to add some logic to error handling. This commit extracts error handling code from sending methods classes, which already do a lot of other stuff, to error mappers which are responsible for creating proper error object (MailerError). This error object is a replacement for assoc. array which already had some special keys for certain usecases and can not be properly type hinted. [MAILPOET-1154]
This commit is contained in:
23
lib/Mailer/Methods/ErrorMappers/AmazonSESMapper.php
Normal file
23
lib/Mailer/Methods/ErrorMappers/AmazonSESMapper.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace MailPoet\Mailer\Methods\ErrorMappers;
|
||||
|
||||
use MailPoet\Mailer\MailerError;
|
||||
use MailPoet\Mailer\Mailer;
|
||||
|
||||
class AmazonSESMapper {
|
||||
use ConnectionErrorMapperTrait;
|
||||
|
||||
function getErrorFromException(\Exception $e) {
|
||||
return new MailerError(MailerError::OPERATION_SEND, MailerError::LEVEL_HARD, $e->getMessage());
|
||||
}
|
||||
|
||||
function getErrorFromResponse($response, $subscriber, $extra_params) {
|
||||
$response = ($response) ?
|
||||
$response->Error->Message->__toString() :
|
||||
sprintf(__('%s has returned an unknown error.', 'mailpoet'), Mailer::METHOD_AMAZONSES);
|
||||
if(empty($extra_params['test_email'])) {
|
||||
$response .= sprintf(' %s: %s', __('Unprocessed subscriber', 'mailpoet'), $subscriber);
|
||||
}
|
||||
return new MailerError(MailerError::OPERATION_SEND, MailerError::LEVEL_HARD, $response);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user