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:
Rostislav Wolny
2018-08-30 10:42:58 +02:00
parent 8cf5d17cfd
commit 0923c892c1
22 changed files with 517 additions and 211 deletions

View File

@ -34,7 +34,7 @@ class Mailer extends APIEndpoint {
if($result['response'] === false) {
$error = sprintf(
__('The email could not be sent: %s', 'mailpoet'),
$result['error_message']
$result['error']->getMessage()
);
return $this->errorResponse(array(APIError::BAD_REQUEST => $error));
} else {
@ -46,4 +46,4 @@ class Mailer extends APIEndpoint {
MailerLog::resumeSending();
return $this->successResponse(null);
}
}
}