Skip to content

Commit e1959fb

Browse files
committed
[Mailer] fixed Mailgun support when a response is not JSON as expected
1 parent 78df840 commit e1959fb

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Mailgun/Http/Api/MailgunTransport.php

Lines 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

Mailgun/Http/MailgunTransport.php

Lines 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)