From 5c76c6a7df784533fbfa35e051d59e094ffc6600 Mon Sep 17 00:00:00 2001 From: dumityty Date: Fri, 26 Feb 2021 09:26:43 +0000 Subject: [PATCH 1/2] skip json error checking if response is in plaintext --- src/Adapter/Guzzle.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Adapter/Guzzle.php b/src/Adapter/Guzzle.php index a7d8ad1c..2dd5a87f 100644 --- a/src/Adapter/Guzzle.php +++ b/src/Adapter/Guzzle.php @@ -92,7 +92,15 @@ public function request(string $method, string $uri, array $data = [], array $he private function checkError(ResponseInterface $response) { - $json = json_decode($response->getBody()); + + $body = (string) $response->getBody(); + + // If first character of the response body is not { then the response is in plain text so need to skip below checks as they fail. + if (strpos($body, '{') !== 0) { + return; + } + + $json = json_decode($body); if (json_last_error() !== JSON_ERROR_NONE) { throw new JSONException(); From 4e22f08b0be3aa7209a092e55c7ec89dceccefbf Mon Sep 17 00:00:00 2001 From: dumityty Date: Fri, 26 Feb 2021 09:29:43 +0000 Subject: [PATCH 2/2] fix coding standard --- src/Adapter/Guzzle.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Adapter/Guzzle.php b/src/Adapter/Guzzle.php index 2dd5a87f..08c7584e 100644 --- a/src/Adapter/Guzzle.php +++ b/src/Adapter/Guzzle.php @@ -92,12 +92,11 @@ public function request(string $method, string $uri, array $data = [], array $he private function checkError(ResponseInterface $response) { - $body = (string) $response->getBody(); // If first character of the response body is not { then the response is in plain text so need to skip below checks as they fail. if (strpos($body, '{') !== 0) { - return; + return; } $json = json_decode($body);