1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Cerbero\JsonApiError\Exceptions; |
||
6 | |||
7 | use Cerbero\JsonApiError\Data\JsonApiErrorData; |
||
8 | use Cerbero\JsonApiError\JsonApiError; |
||
9 | use Exception; |
||
10 | use Illuminate\Contracts\Support\Responsable; |
||
11 | use Symfony\Component\HttpFoundation\Response; |
||
12 | |||
13 | /** |
||
14 | * The exception thrown to render the JSON:API errors. |
||
15 | */ |
||
16 | class JsonApiException extends Exception implements Responsable |
||
17 | { |
||
18 | /** |
||
19 | * @var JsonApiErrorData[] $errors |
||
20 | */ |
||
21 | public readonly array $errors; |
||
22 | |||
23 | /** |
||
24 | * Instantiate the class. |
||
25 | */ |
||
26 | 1 | public function __construct(JsonApiErrorData ...$errors) |
|
27 | { |
||
28 | 1 | $this->errors = $errors; |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
29 | } |
||
30 | |||
31 | /** |
||
32 | * Render the JSON:API errors. |
||
33 | * |
||
34 | * @param \Illuminate\Http\Request $request |
||
35 | */ |
||
36 | 1 | public function toResponse($request): Response |
|
37 | { |
||
38 | 1 | return (new JsonApiError(...$this->errors))->toResponse($request); |
|
39 | } |
||
40 | } |
||
41 |