Skip to content

Commit 995f952

Browse files
committed
Merge branch '4.3' into 4.4
* 4.3: [Mailer] fixed Mailgun support when a response is not JSON as expected
2 parents c649974 + e1959fb commit 995f952

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

Mailgun/Transport/MailgunApiTransport.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ protected function doSendApi(Email $email, SmtpEnvelope $envelope): ResponseInte
6262
]);
6363

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

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

7072
return $response;

Mailgun/Transport/MailgunHttpTransport.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ protected function doSendHttp(SentMessage $message): ResponseInterface
6565
]);
6666

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

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

7375
return $response;

MailgunApiTransport.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ protected function doSendApi(Email $email, SmtpEnvelope $envelope): ResponseInte
6262
]);
6363

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

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

7072
return $response;

MailgunHttpTransport.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ protected function doSendHttp(SentMessage $message): ResponseInterface
6565
]);
6666

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

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

7375
return $response;

0 commit comments

Comments
 (0)