Skip to content

Commit 21e23f3

Browse files
committedFeb 28, 2022
errourCount shows the real count of errors
1 parent eaf1eb9 commit 21e23f3

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed
 

‎src/Error/JsonApiExceptionRenderer.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,21 @@ class JsonApiExceptionRenderer extends ExceptionRenderer
1010
{
1111
public function jsonApi(JsonApiException $error)
1212
{
13+
$errors = $error->getRequestErrors();
14+
$errorsCount = 0;
15+
foreach ($errors as $err) {
16+
if (count($err)) {
17+
$errorsCount++;
18+
}
19+
}
20+
1321
$response = $this->controller->getResponse();
1422
$data = [
1523
'message' => $error->getMessage(),
1624
'url' => $this->controller->getRequest()->getRequestTarget(),
1725
'line' => $error->getLine(),
18-
'errorCount' => count(Hash::flatten($error->getRequestErrors())),
19-
'errors' => $error->getRequestErrors(),
26+
'errorCount' => $errorsCount,
27+
'errors' => $errors,
2028
];
2129

2230
return $response

‎tests/TestCase/JsonApiExceptionRendererTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public function testJsonApiWithEntitiesError()
4242
$firstEntity->setError('name', ['_empty' => $this->validationError]);
4343
$secondEntity = new Entity();
4444
$secondEntity->setError('name', ['_empty' => $this->validationError]);
45-
$entities = [$firstEntity, $secondEntity];
45+
$thirdEntity = new Entity();
46+
$entities = [$firstEntity, $secondEntity, $thirdEntity];
4647
$exception = new JsonApiException($entities, $this->message);
4748

4849
$request = (new ServerRequest())

0 commit comments

Comments
 (0)