Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix json Exception #359

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 12 additions & 0 deletions src/Exceptions/UnserializableResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,23 @@

final class UnserializableResponse extends Exception
{
private string $content;

/**
* Creates a new Exception instance.
*/
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;
}
}
4 changes: 3 additions & 1 deletion src/Transporters/HttpTransporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Loading