Skip to content

Commit

Permalink
bug #33432 [Mailer] Fix Mailgun support when a response is not JSON a…
Browse files Browse the repository at this point in the history
…s expected (fabpot)

This PR was merged into the 4.3 branch.

Discussion
----------

[Mailer] Fix Mailgun support when a response is not JSON as expected

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #32043
| License       | MIT
| Doc PR        | n/a

Sometimes, like when getting a 401, the Mailgun API does not respond with JSON :(

Commits
-------

3b2db42 [Mailer] fixed Mailgun support when a response is not JSON as expected
  • Loading branch information
fabpot committed Sep 2, 2019
2 parents d05e497 + 3b2db42 commit ca16f52
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Expand Up @@ -58,9 +58,11 @@ protected function doSendEmail(Email $email, SmtpEnvelope $envelope): void
]);

if (200 !== $response->getStatusCode()) {
$error = $response->toArray(false);
if ('application/json' === $response->getHeaders(false)['content-type'][0]) {
throw new TransportException(sprintf('Unable to send an email: %s (code %s).', $response->toArray(false)['message'], $response->getStatusCode()));
}

throw new TransportException(sprintf('Unable to send an email: %s (code %s).', $error['message'], $response->getStatusCode()));
throw new TransportException(sprintf('Unable to send an email: %s (code %s).', $response->getContent(false), $response->getStatusCode()));
}
}

Expand Down
Expand Up @@ -59,9 +59,11 @@ protected function doSend(SentMessage $message): void
]);

if (200 !== $response->getStatusCode()) {
$error = $response->toArray(false);
if ('application/json' === $response->getHeaders(false)['content-type'][0]) {
throw new TransportException(sprintf('Unable to send an email: %s (code %s).', $response->toArray(false)['message'], $response->getStatusCode()));
}

throw new TransportException(sprintf('Unable to send an email: %s (code %s).', $error['message'], $response->getStatusCode()));
throw new TransportException(sprintf('Unable to send an email: %s (code %s).', $response->getContent(false), $response->getStatusCode()));
}
}
}

0 comments on commit ca16f52

Please sign in to comment.