From 570020913cd58ab6d5e016c755494916d066149f Mon Sep 17 00:00:00 2001 From: chengxs Date: Wed, 20 Mar 2024 10:24:27 +0000 Subject: [PATCH 1/3] fix json Exception --- src/Exceptions/UnserializableResponse.php | 11 +++++++++++ src/Transporters/HttpTransporter.php | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Exceptions/UnserializableResponse.php b/src/Exceptions/UnserializableResponse.php index 2f9d0643..55dba145 100644 --- a/src/Exceptions/UnserializableResponse.php +++ b/src/Exceptions/UnserializableResponse.php @@ -9,6 +9,7 @@ final class UnserializableResponse extends Exception { + protected string $content; /** * Creates a new Exception instance. */ @@ -16,4 +17,14 @@ public function __construct(JsonException $exception) { parent::__construct($exception->getMessage(), 0, $exception); } + + public function getContent(): string + { + return $this->content; + } + + public function setContent(string $content): void + { + $this->content = $content; + } } diff --git a/src/Transporters/HttpTransporter.php b/src/Transporters/HttpTransporter.php index 37ed0d7c..f7656d24 100644 --- a/src/Transporters/HttpTransporter.php +++ b/src/Transporters/HttpTransporter.php @@ -60,7 +60,9 @@ public function requestObject(Payload $payload): Response /** @var array{error?: array{message: string, type: string, code: string}} $data */ $data = json_decode($contents, true, flags: JSON_THROW_ON_ERROR); } catch (JsonException $jsonException) { - throw new UnserializableResponse($jsonException); + $unserializableResponse = new UnserializableResponse($jsonException); + $unserializableResponse->setContent($contents); + throw $unserializableResponse; } return Response::from($data, $response->getHeaders()); From 0f6eac0d2ed44913fd956c4cf55c83b074acded8 Mon Sep 17 00:00:00 2001 From: chengxs Date: Wed, 20 Mar 2024 10:28:31 +0000 Subject: [PATCH 2/3] pint --- src/Exceptions/UnserializableResponse.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Exceptions/UnserializableResponse.php b/src/Exceptions/UnserializableResponse.php index 55dba145..92554ff2 100644 --- a/src/Exceptions/UnserializableResponse.php +++ b/src/Exceptions/UnserializableResponse.php @@ -10,6 +10,7 @@ final class UnserializableResponse extends Exception { protected string $content; + /** * Creates a new Exception instance. */ From 5cc0ebf3c5e544b5f5aee102c2fcf9c3c1f952b2 Mon Sep 17 00:00:00 2001 From: chengxs Date: Wed, 20 Mar 2024 11:17:46 +0000 Subject: [PATCH 3/3] private --- src/Exceptions/UnserializableResponse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Exceptions/UnserializableResponse.php b/src/Exceptions/UnserializableResponse.php index 92554ff2..2da20676 100644 --- a/src/Exceptions/UnserializableResponse.php +++ b/src/Exceptions/UnserializableResponse.php @@ -9,7 +9,7 @@ final class UnserializableResponse extends Exception { - protected string $content; + private string $content; /** * Creates a new Exception instance.