bug #33432 [Mailer] Fix Mailgun support when a response is not JSON as 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
-------
3b2db425f6
[Mailer] fixed Mailgun support when a response is not JSON as expected
This commit is contained in:
commit
ca16f5278e
@ -58,9 +58,11 @@ class MailgunTransport extends AbstractApiTransport
|
||||
]);
|
||||
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,9 +59,11 @@ class MailgunTransport extends AbstractHttpTransport
|
||||
]);
|
||||
|
||||
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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user