Skip to content

Commit

Permalink
Add context to exception only if exists
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar authored and Milan Felix 艩ulc committed Feb 9, 2019
1 parent 8a119b4 commit 22a1e60
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Transformer/JsonTransformer.php
Expand Up @@ -58,7 +58,9 @@ protected function extractException(ApiRequest $request, ApiResponse $response,

if ($exception instanceof ClientErrorException || $exception instanceof ServerErrorException) {
$data['exception'] = $exception->getMessage();
$data['context'] = $exception->getContext();
if ($exception->getContext() !== null) {
$data['context'] = $exception->getContext();
}
} else {
$data['exception'] = $this->debug ? $exception->getMessage() : 'Application encountered an internal error. Please try again later.';
}
Expand Down
5 changes: 4 additions & 1 deletion src/Transformer/JsonUnifyTransformer.php
Expand Up @@ -98,9 +98,12 @@ protected function processClientError(ClientErrorException $exception, ApiReques
$data = [
'code' => $exception->getCode(),
'error' => $exception->getMessage(),
'context' => $exception->getContext(),
];

if ($exception->getContext() !== null) {
$data['context'] = $exception->getContext();
}

return $response
->withStatus($exception->getCode())
->withAttribute(ResponseAttributes::ATTR_ENTITY, ArrayEntity::from([
Expand Down

0 comments on commit 22a1e60

Please sign in to comment.