Skip to content
This repository has been archived by the owner on Jun 15, 2021. It is now read-only.

Commit

Permalink
feat: put all response document errors into the HttpException wheneve…
Browse files Browse the repository at this point in the history
…r a server error occurs
  • Loading branch information
chris-doehring committed Jun 22, 2020
1 parent f30279b commit dc0af71
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/JsonApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,19 @@ public function execute(RequestInterface $request, bool $exceptionOnFatalError =
$response = $this->responseFactory->createResponse($httpResponse);

if ($exceptionOnFatalError && $response->status() >= 400) {
$message = 'Non successful http status returned (' . $response->status() . ').';
$e = new HttpException(
$response->status(),
'Non successful http status returned (' . $response->status() . ').'
);

$document = $response->document();
if ($document && !$document->errors()->isEmpty()) {
foreach ($document->errors()->all() as $error) {
$message .= '\n' . $error->title();
$e->errors()->add($error);
}
}

throw new HttpException($response->status(), $message);
throw $e;
}

return $response;
Expand Down

0 comments on commit dc0af71

Please sign in to comment.