Skip to content

Commit 9f973da

Browse files
committed
handling entity arrays
1 parent 36bccbb commit 9f973da

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Error/Exception/JsonApiException.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@ class JsonApiException extends BadRequestException
99
{
1010
protected $requestErrors;
1111

12-
public function __construct(EntityInterface $entity, $message = null, $code = 400)
12+
public function __construct(EntityInterface|array $entity, $message = null, $code = 400)
1313
{
14-
$this->requestErrors = $entity->getErrors();
14+
if (is_array($entity)) {
15+
foreach ($entity as $ent) {
16+
$this->requestErrors[] = $ent->getErrors();
17+
}
18+
}
19+
if (!is_array($entity)) {
20+
$this->requestErrors = $entity->getErrors();
21+
}
1522

1623
if ($message === null) {
1724
$message = 'Bad Request';

0 commit comments

Comments
 (0)