AmazonSESMapper.php
3 years ago
BlacklistErrorMapperTrait.php
3 years ago
ConnectionErrorMapperTrait.php
3 years ago
MailPoetMapper.php
1 year ago
PHPMailMapper.php
4 years ago
PHPMailerMapper.php
3 years ago
SMTPMapper.php
4 years ago
SendGridMapper.php
3 years ago
index.php
3 years ago
SendGridMapper.php
32 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Mailer\Methods\ErrorMappers; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Mailer\Mailer; |
| 9 | use MailPoet\Mailer\MailerError; |
| 10 | use MailPoet\Mailer\SubscriberError; |
| 11 | |
| 12 | class SendGridMapper { |
| 13 | use BlacklistErrorMapperTrait; |
| 14 | use ConnectionErrorMapperTrait; |
| 15 | |
| 16 | const METHOD = Mailer::METHOD_SENDGRID; |
| 17 | |
| 18 | public function getErrorFromResponse($response, $subscriber) { |
| 19 | $response = (!empty($response['errors'][0])) ? |
| 20 | $response['errors'][0] : |
| 21 | // translators: %s is the name of the method. |
| 22 | sprintf(__('%s has returned an unknown error.', 'mailpoet'), Mailer::METHOD_SENDGRID); |
| 23 | |
| 24 | $level = MailerError::LEVEL_HARD; |
| 25 | if (strpos($response, 'Invalid email address') === 0) { |
| 26 | $level = MailerError::LEVEL_SOFT; |
| 27 | } |
| 28 | $subscriberErrors = [new SubscriberError($subscriber, null)]; |
| 29 | return new MailerError(MailerError::OPERATION_SEND, $level, $response, null, $subscriberErrors); |
| 30 | } |
| 31 | } |
| 32 |