Skip to content

Commit e10cfc4

Browse files
committed
set more data for the response
1 parent 90f859c commit e10cfc4

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/Error/JsonApiExceptionRenderer.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,26 @@
22

33
namespace JsonApiException\Error;
44

5+
use Cake\Utility\Hash;
56
use Cake\Error\ExceptionRenderer;
7+
use JsonApiException\Error\Exception\JsonApiException;
68

79
class JsonApiExceptionRenderer extends ExceptionRenderer
810
{
9-
public function jsonApi($exception)
11+
public function jsonApi(JsonApiException $error)
1012
{
1113
$response = $this->controller->getResponse();
14+
$data = [
15+
'message' => $error->getMessage(),
16+
'url' => $this->controller->getRequest()->getRequestTarget(),
17+
'line' => $error->getLine(),
18+
'errorCount' => count(Hash::flatten($error->getRequestErrors())),
19+
'errors' => $error->getRequestErrors(),
20+
];
21+
1222
return $response
13-
->withStringBody(json_encode(['errors' => $exception->getRequestErrors()]))
14-
->withStatus(406)
23+
->withStringBody(json_encode($data))
24+
->withStatus($error->getCode())
1525
->withType('application/json');
1626
}
1727
}

0 commit comments

Comments
 (0)