[Mailer] fixed Mailgun support when a response is not JSON as expected

This commit is contained in:
Fabien Potencier 2019-09-02 17:15:54 +02:00
parent d423b0f473
commit 3b2db425f6
2 changed files with 8 additions and 4 deletions

View File

@ -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()));
}
}

View File

@ -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()));
}
}
}