From 3b2db425f6fe7a11611160004a7d122afae7c43e Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 2 Sep 2019 17:15:54 +0200 Subject: [PATCH] [Mailer] fixed Mailgun support when a response is not JSON as expected --- .../Mailer/Bridge/Mailgun/Http/Api/MailgunTransport.php | 6 ++++-- .../Mailer/Bridge/Mailgun/Http/MailgunTransport.php | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Mailer/Bridge/Mailgun/Http/Api/MailgunTransport.php b/src/Symfony/Component/Mailer/Bridge/Mailgun/Http/Api/MailgunTransport.php index 9da64c4e2be1..ac06c005cd19 100644 --- a/src/Symfony/Component/Mailer/Bridge/Mailgun/Http/Api/MailgunTransport.php +++ b/src/Symfony/Component/Mailer/Bridge/Mailgun/Http/Api/MailgunTransport.php @@ -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())); } } diff --git a/src/Symfony/Component/Mailer/Bridge/Mailgun/Http/MailgunTransport.php b/src/Symfony/Component/Mailer/Bridge/Mailgun/Http/MailgunTransport.php index 1cc0f25dec94..819460ba4058 100644 --- a/src/Symfony/Component/Mailer/Bridge/Mailgun/Http/MailgunTransport.php +++ b/src/Symfony/Component/Mailer/Bridge/Mailgun/Http/MailgunTransport.php @@ -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())); } } }