Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 77b2409

Browse filesBrowse files
NyholmOskarStark
authored andcommitted
[Notifier] [5.3] Make sure Http TransportException is not leaking
1 parent 387979d commit 77b2409
Copy full SHA for 77b2409

File tree

11 files changed

+85
-11
lines changed
Filter options

11 files changed

+85
-11
lines changed

‎src/Symfony/Component/Notifier/Bridge/AllMySms/AllMySmsTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/AllMySms/AllMySmsTransport.php
+8-1Lines 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
/**
@@ -70,7 +71,13 @@ protected function doSend(MessageInterface $message): SentMessage
7071
],
7172
]);
7273

73-
if (201 !== $response->getStatusCode()) {
74+
try {
75+
$statusCode = $response->getStatusCode();
76+
} catch (TransportExceptionInterface $e) {
77+
throw new TransportException('Could not reach the remote AllMySms server.', $response, 0, $e);
78+
}
79+
80+
if (201 !== $statusCode) {
7481
$error = $response->toArray(false);
7582

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

‎src/Symfony/Component/Notifier/Bridge/Clickatell/ClickatellTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Clickatell/ClickatellTransport.php
+8-1Lines 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
/**
@@ -74,7 +75,13 @@ protected function doSend(MessageInterface $message): SentMessage
7475
],
7576
]);
7677

77-
if (202 === $response->getStatusCode()) {
78+
try {
79+
$statusCode = $response->getStatusCode();
80+
} catch (TransportExceptionInterface $e) {
81+
throw new TransportException('Could not reach the remote Clicktell server.', $response, 0, $e);
82+
}
83+
84+
if (202 === $statusCode) {
7885
$result = $response->toArray();
7986
$sentMessage = new SentMessage($message, (string) $this);
8087
$sentMessage->setMessageId($result['data']['message'][0]['apiMessageId']);

‎src/Symfony/Component/Notifier/Bridge/GatewayApi/GatewayApiTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/GatewayApi/GatewayApiTransport.php
+7-1Lines changed: 7 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
/**
@@ -65,7 +66,12 @@ protected function doSend(MessageInterface $message): SentMessage
6566
],
6667
]);
6768

68-
$statusCode = $response->getStatusCode();
69+
try {
70+
$statusCode = $response->getStatusCode();
71+
} catch (TransportExceptionInterface $e) {
72+
throw new TransportException('Could not reach the remote GatewayApi server.', $response, 0, $e);
73+
}
74+
6975
if (200 !== $statusCode) {
7076
throw new TransportException(sprintf('Unable to send the SMS: error %d.', $statusCode), $response);
7177
}

‎src/Symfony/Component/Notifier/Bridge/Gitter/GitterTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Gitter/GitterTransport.php
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Notifier\Message\SentMessage;
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
/**
@@ -66,7 +67,11 @@ protected function doSend(MessageInterface $message): SentMessage
6667
],
6768
]);
6869

69-
$result = $response->toArray(false);
70+
try {
71+
$result = $response->toArray(false);
72+
} catch (TransportExceptionInterface $e) {
73+
throw new TransportException('Could not reach the remote Gitter server.', $response, 0, $e);
74+
}
7075

7176
if (200 !== $response->getStatusCode()) {
7277
throw new TransportException(sprintf('Unable to post the Gitter message: "%s".', $result['error']), $response);

‎src/Symfony/Component/Notifier/Bridge/Iqsms/IqsmsTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Iqsms/IqsmsTransport.php
+7-1Lines changed: 7 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
/**
@@ -71,7 +72,12 @@ protected function doSend(MessageInterface $message): SentMessage
7172
],
7273
]);
7374

74-
$result = $response->toArray(false);
75+
try {
76+
$result = $response->toArray(false);
77+
} catch (TransportExceptionInterface $e) {
78+
throw new TransportException('Could not reach the remote Iqsms server.', $response, 0, $e);
79+
}
80+
7581
foreach ($result['messages'] as $msg) {
7682
if ('accepted' !== $msg['status']) {
7783
throw new TransportException(sprintf('Unable to send the SMS: "%s".', $msg['status']), $response);

‎src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php
+8-1Lines 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
/**
@@ -117,7 +118,13 @@ protected function doSend(MessageInterface $message): SentMessage
117118
]
118119
);
119120

120-
if (200 !== $response->getStatusCode()) {
121+
try {
122+
$statusCode = $response->getStatusCode();
123+
} catch (TransportExceptionInterface $e) {
124+
throw new TransportException('Could not reach the remote LightSms server.', $response, 0, $e);
125+
}
126+
127+
if (200 !== $statusCode) {
121128
throw new TransportException('Unable to send the SMS.', $response);
122129
}
123130

‎src/Symfony/Component/Notifier/Bridge/MessageBird/MessageBirdTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/MessageBird/MessageBirdTransport.php
+8-1Lines 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
/**
@@ -64,7 +65,13 @@ protected function doSend(MessageInterface $message): SentMessage
6465
],
6566
]);
6667

67-
if (201 !== $response->getStatusCode()) {
68+
try {
69+
$statusCode = $response->getStatusCode();
70+
} catch (TransportExceptionInterface $e) {
71+
throw new TransportException('Could not reach the remote MessageBird server.', $response, 0, $e);
72+
}
73+
74+
if (201 !== $statusCode) {
6875
if (!isset($response->toArray(false)['errors'])) {
6976
throw new TransportException('Unable to send the SMS.', $response);
7077
}

‎src/Symfony/Component/Notifier/Bridge/MicrosoftTeams/MicrosoftTeamsTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/MicrosoftTeams/MicrosoftTeamsTransport.php
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Notifier\Message\SentMessage;
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
/**
@@ -64,14 +65,20 @@ protected function doSend(MessageInterface $message): SentMessage
6465
],
6566
]);
6667

68+
try {
69+
$statusCode = $response->getStatusCode();
70+
} catch (TransportExceptionInterface $e) {
71+
throw new TransportException('Could not reach the remote MicrosoftTeams server.', $response, 0, $e);
72+
}
73+
6774
$requestId = $response->getHeaders(false)['request-id'][0] ?? null;
6875
if (null === $requestId) {
6976
$originalContent = $message->getSubject();
7077

7178
throw new TransportException(sprintf('Unable to post the Microsoft Teams message: "%s" (request-id not found).', $originalContent), $response);
7279
}
7380

74-
if (200 !== $response->getStatusCode()) {
81+
if (200 !== $statusCode) {
7582
$errorMessage = $response->getContent(false);
7683
$originalContent = $message->getSubject();
7784

‎src/Symfony/Component/Notifier/Bridge/Octopush/OctopushTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Octopush/OctopushTransport.php
+8-1Lines 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
/**
@@ -74,7 +75,13 @@ protected function doSend(MessageInterface $message): SentMessage
7475
],
7576
]);
7677

77-
if (200 !== $response->getStatusCode()) {
78+
try {
79+
$statusCode = $response->getStatusCode();
80+
} catch (TransportExceptionInterface $e) {
81+
throw new TransportException('Could not reach the remote Octopush server.', $response, 0, $e);
82+
}
83+
84+
if (200 !== $statusCode) {
7885
$error = $response->toArray(false);
7986

8087
throw new TransportException('Unable to send the SMS: '.$error['error_code'], $response);

‎src/Symfony/Component/Notifier/Bridge/SmsBiuras/SmsBiurasTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/SmsBiuras/SmsBiurasTransport.php
+8-1Lines 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
/**
@@ -89,7 +90,13 @@ protected function doSend(MessageInterface $message): SentMessage
8990
],
9091
]);
9192

92-
if (200 !== $response->getStatusCode()) {
93+
try {
94+
$statusCode = $response->getStatusCode();
95+
} catch (TransportExceptionInterface $e) {
96+
throw new TransportException('Could not reach the remote SmsBiuras server.', $response, 0, $e);
97+
}
98+
99+
if (200 !== $statusCode) {
93100
throw new TransportException('Unable to send the SMS.', $response);
94101
}
95102

‎src/Symfony/Component/Notifier/Bridge/SpotHit/SpotHitTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/SpotHit/SpotHitTransport.php
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
use Symfony\Component\Notifier\Transport\AbstractTransport;
2020
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
2121
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
22+
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
23+
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
2224
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
2325
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
2426
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
@@ -81,7 +83,13 @@ protected function doSend(MessageInterface $message): SentMessage
8183
],
8284
]);
8385

84-
$data = json_decode($response->getContent(), true);
86+
try {
87+
$data = $response->toArray();
88+
} catch (TransportExceptionInterface $e) {
89+
throw new TransportException('Could not reach the remote SpotHit server.', $response, 0, $e);
90+
} catch (HttpExceptionInterface | DecodingExceptionInterface $e) {
91+
throw new TransportException('Unexpected reply from the remote SpotHit server.', $response, 0, $e);
92+
}
8593

8694
if (!$data['resultat']) {
8795
$errors = \is_array($data['erreurs']) ? implode(',', $data['erreurs']) : $data['erreurs'];

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.