Skip to content

Commit 4a28597

Browse files
committed
bug #42307 [Mailer] Fixed decode exception when sendgrid response is 202 (rubanooo)
This PR was submitted for the 5.3 branch but it was squashed and merged into the 4.4 branch instead. Discussion ---------- [Mailer] Fixed decode exception when sendgrid response is 202 | Q | A | ------------- | --- | Branch? | 5.4 for features / 4.4, 5.2 or 5.3 for bug fixes <!-- see below --> | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #42306 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Never break backward compatibility (see https://symfony.com/bc). - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.) - Features and deprecations must be submitted against branch 5.x. - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry --> Commits ------- 9c6d31a [Mailer] Fixed decode exception when sendgrid response is 202
2 parents 192e360 + 9c6d31a commit 4a28597

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)