Skip to content
Permalink
Browse files

Add context to exception only if exists

  • Loading branch information...
mabar authored and f3l1x committed Feb 8, 2019
1 parent 8a119b4 commit 22a1e60b4977fc4ed5f035691ed76484761c8568
Showing with 7 additions and 2 deletions.
  1. +3 −1 src/Transformer/JsonTransformer.php
  2. +4 −1 src/Transformer/JsonUnifyTransformer.php
@@ -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.';
}
@@ -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([

0 comments on commit 22a1e60

Please sign in to comment.
You can’t perform that action at this time.