Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ca16f52

Browse filesBrowse files
committed
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 ------- 3b2db42 [Mailer] fixed Mailgun support when a response is not JSON as expected
2 parents d05e497 + 3b2db42 commit ca16f52
Copy full SHA for ca16f52

File tree

Expand file treeCollapse file tree

2 files changed

+8
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+8
-4
lines changed

‎src/Symfony/Component/Mailer/Bridge/Mailgun/Http/Api/MailgunTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Bridge/Mailgun/Http/Api/MailgunTransport.php
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ protected function doSendEmail(Email $email, SmtpEnvelope $envelope): void
5858
]);
5959

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

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

‎src/Symfony/Component/Mailer/Bridge/Mailgun/Http/MailgunTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Bridge/Mailgun/Http/MailgunTransport.php
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ protected function doSend(SentMessage $message): void
5959
]);
6060

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

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.