Skip to content

Commit 88e099a

Browse files
committed
Fixed decode exception when sendgrid response is 202
1 parent a1055ae commit 88e099a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/Symfony/Component/Mailer/Bridge/Sendgrid/Transport/SendgridApiTransport.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,18 @@ protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $e
5454

5555
try {
5656
$statusCode = $response->getStatusCode();
57-
$result = $response->toArray(false);
58-
} catch (DecodingExceptionInterface $e) {
59-
throw new HttpTransportException('Unable to send an email: '.$response->getContent(false).sprintf(' (code %d).', $statusCode), $response);
6057
} catch (TransportExceptionInterface $e) {
6158
throw new HttpTransportException('Could not reach the remote Sendgrid server.', $response, 0, $e);
6259
}
6360

6461
if (202 !== $statusCode) {
65-
throw new HttpTransportException('Unable to send an email: '.implode('; ', array_column($result['errors'], 'message')).sprintf(' (code %d).', $statusCode), $response);
62+
try {
63+
$result = $response->toArray(false);
64+
65+
throw new HttpTransportException('Unable to send an email: ' . implode('; ', array_column($result['errors'], 'message')) . sprintf(' (code %d).', $statusCode), $response);
66+
} catch (DecodingExceptionInterface $e) {
67+
throw new HttpTransportException('Unable to send an email: ' . $response->getContent(false) . sprintf(' (code %d).', $statusCode), $response);
68+
}
6669
}
6770

6871
$sentMessage->setMessageId($response->getHeaders(false)['x-message-id'][0]);

0 commit comments

Comments
 (0)