Skip to content

Commit f382fac

Browse files
[1.15] Use exception chaining to provide the decoding error information (#705)
* Use exception chaining to provide the decoding error information * Apply fixes from StyleCI --------- Co-authored-by: StyleCI Bot <bot@styleci.io>
1 parent 9dce1e4 commit f382fac

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/Communication/Connection.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -372,14 +372,11 @@ public function processAllEvents(): void
372372
*/
373373
private function dispatchMessage(string $message, ?Session $session = null)
374374
{
375-
// responses come as json string
376-
$response = \json_decode($message, true);
377-
378-
// if json not valid throw exception
379-
$jsonError = \json_last_error();
380-
if (\JSON_ERROR_NONE !== $jsonError) {
375+
try {
376+
$response = \json_decode($message, true, 512, \JSON_THROW_ON_ERROR);
377+
} catch (\JsonException $e) {
381378
if ($this->isStrict()) {
382-
throw new CannotReadResponse(\sprintf('Response from chrome remote interface is not a valid json response. JSON error: %s', $jsonError));
379+
throw new CannotReadResponse('Response from chrome remote interface is not a valid JSON response', 0, $e);
383380
}
384381

385382
return false;

0 commit comments

Comments
 (0)