]> BookStack Code Mirror - bookstack/blob - app/Exceptions/JsonDebugException.php
OIDC: Updated picture fetch implementation during review
[bookstack] / app / Exceptions / JsonDebugException.php
1 <?php
2
3 namespace BookStack\Exceptions;
4
5 use Exception;
6 use Illuminate\Http\JsonResponse;
7 use Illuminate\Contracts\Support\Responsable;
8
9 class JsonDebugException extends Exception implements Responsable
10 {
11     protected array $data;
12
13     /**
14      * JsonDebugException constructor.
15      */
16     public function __construct(array $data)
17     {
18         $this->data = $data;
19         parent::__construct();
20     }
21
22     /**
23      * Convert this exception into a response.
24      * We add a manual data conversion to UTF8 to ensure any binary data is presentable as a JSON string.
25      */
26     public function toResponse($request): JsonResponse
27     {
28         $cleaned = mb_convert_encoding($this->data, 'UTF-8');
29
30         return response()->json($cleaned);
31     }
32 }