Add soft level errors distinction for PHPMail method

[MAILPOET-1154]
This commit is contained in:
Rostislav Wolny
2018-09-11 14:55:39 +02:00
parent 45433c9deb
commit fe69b56692
3 changed files with 45 additions and 3 deletions

View File

@ -8,8 +8,16 @@ use MailPoet\Mailer\SubscriberError;
class PHPMailMapper {
use ConnectionErrorMapperTrait;
function getErrorFromException(\Exception $e) {
return new MailerError(MailerError::OPERATION_SEND, MailerError::LEVEL_HARD, $e->getMessage());
function getErrorFromException(\Exception $e, $subscriber, $extra_params) {
$level = MailerError::LEVEL_HARD;
if(strpos($e->getMessage(), 'Invalid address') === 0) {
$level = MailerError::LEVEL_SOFT;
}
$subscriber_errors = [];
if(empty($extra_params['test_email'])) {
$subscriber_errors[] = new SubscriberError($subscriber, null);
}
return new MailerError(MailerError::OPERATION_SEND, $level, $e->getMessage(), null, $subscriber_errors);
}
function getErrorForSubscriber($subscriber, $extra_params) {