Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix(tests): Handle JSON exceptions
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Dec 8, 2023
commit 91f911c5b2101b237b635a6cf9607b8dfa7762ac
12 changes: 10 additions & 2 deletions lib/Push.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,13 +501,21 @@ protected function sendNotificationsToProxies(): void {
$response = $client->post($proxyServer . '/notifications', $requestData);
$status = $response->getStatusCode();
$body = (string) $response->getBody();
$bodyData = json_decode($body, true, flags: JSON_THROW_ON_ERROR);
try {
$bodyData = json_decode($body, true);
} catch (\JsonException $e) {
$bodyData = null;
}
} catch (ClientException $e) {
// Server responded with 4xx (400 Bad Request mostlikely)
$response = $e->getResponse();
$status = $response->getStatusCode();
$body = $response->getBody()->getContents();
$bodyData = json_decode($body, true, flags: JSON_THROW_ON_ERROR);
try {
$bodyData = json_decode($body, true);
} catch (\JsonException $e) {
$bodyData = null;
}
} catch (ServerException $e) {
// Server responded with 5xx
$response = $e->getResponse();
Expand Down