Skip to content

Commit

Permalink
errourCount shows the real count of errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rrd108 committed Feb 28, 2022
1 parent eaf1eb9 commit 21e23f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/Error/JsonApiExceptionRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@ class JsonApiExceptionRenderer extends ExceptionRenderer
{
public function jsonApi(JsonApiException $error)
{
$errors = $error->getRequestErrors();
$errorsCount = 0;
foreach ($errors as $err) {
if (count($err)) {
$errorsCount++;
}
}

$response = $this->controller->getResponse();
$data = [
'message' => $error->getMessage(),
'url' => $this->controller->getRequest()->getRequestTarget(),
'line' => $error->getLine(),
'errorCount' => count(Hash::flatten($error->getRequestErrors())),
'errors' => $error->getRequestErrors(),
'errorCount' => $errorsCount,
'errors' => $errors,
];

return $response
Expand Down
3 changes: 2 additions & 1 deletion tests/TestCase/JsonApiExceptionRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public function testJsonApiWithEntitiesError()
$firstEntity->setError('name', ['_empty' => $this->validationError]);
$secondEntity = new Entity();
$secondEntity->setError('name', ['_empty' => $this->validationError]);
$entities = [$firstEntity, $secondEntity];
$thirdEntity = new Entity();
$entities = [$firstEntity, $secondEntity, $thirdEntity];
$exception = new JsonApiException($entities, $this->message);

$request = (new ServerRequest())
Expand Down

0 comments on commit 21e23f3

Please sign in to comment.