Skip to content

Commit c154d2a

Browse files
committed
bug #42182 [Notifier] Make sure Http TransportException is not leaking (Nyholm)
This PR was squashed before being merged into the 5.2 branch. Discussion ---------- [Notifier] Make sure Http TransportException is not leaking | Q | A | ------------- | --- | Branch? | 5.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | We dont want the notifier to throw exceptions from the http-client component. This will make sure to catch such exceptions and rethrow the proper TransportException from the Notifier component. Commits ------- 1eed48892d [Notifier] Make sure Http TransportException is not leaking
2 parents 23a2a29 + 783c404 commit c154d2a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

SmsapiTransport.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Notifier\Message\SmsMessage;
1919
use Symfony\Component\Notifier\Transport\AbstractTransport;
2020
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
21+
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
2122
use Symfony\Contracts\HttpClient\HttpClientInterface;
2223

2324
/**
@@ -67,7 +68,13 @@ protected function doSend(MessageInterface $message): SentMessage
6768
],
6869
]);
6970

70-
if (200 !== $response->getStatusCode()) {
71+
try {
72+
$statusCode = $response->getStatusCode();
73+
} catch (TransportExceptionInterface $e) {
74+
throw new TransportException('Could not reach the remote Smsapi server.', $response, 0, $e);
75+
}
76+
77+
if (200 !== $statusCode) {
7178
$error = $response->toArray(false);
7279

7380
throw new TransportException(sprintf('Unable to send the SMS: "%s".', $error['message']), $response);

0 commit comments

Comments
 (0)