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