diff --git a/src/Exceptions/UnserializableResponse.php b/src/Exceptions/UnserializableResponse.php index 2f9d0643..2da20676 100644 --- a/src/Exceptions/UnserializableResponse.php +++ b/src/Exceptions/UnserializableResponse.php @@ -9,6 +9,8 @@ final class UnserializableResponse extends Exception { + private string $content; + /** * Creates a new Exception instance. */ @@ -16,4 +18,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());