2021-06-26 23:23:15 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Exceptions;
|
2019-11-17 21:26:43 +08:00
|
|
|
|
|
|
|
use Exception;
|
2022-02-24 22:16:09 +08:00
|
|
|
use Illuminate\Http\JsonResponse;
|
2023-06-14 20:30:14 +08:00
|
|
|
use Illuminate\Contracts\Support\Responsable;
|
2019-11-17 21:26:43 +08:00
|
|
|
|
2023-06-14 20:30:14 +08:00
|
|
|
class JsonDebugException extends Exception implements Responsable
|
2019-11-17 21:26:43 +08:00
|
|
|
{
|
2022-02-24 22:16:09 +08:00
|
|
|
protected array $data;
|
2019-11-17 21:26:43 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* JsonDebugException constructor.
|
|
|
|
*/
|
2022-02-24 22:16:09 +08:00
|
|
|
public function __construct(array $data)
|
2019-11-17 21:26:43 +08:00
|
|
|
{
|
|
|
|
$this->data = $data;
|
2022-02-24 22:16:09 +08:00
|
|
|
parent::__construct();
|
2019-11-17 21:26:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-05-09 22:57:50 +08:00
|
|
|
* Convert this exception into a response.
|
|
|
|
* We add a manual data conversion to UTF8 to ensure any binary data is presentable as a JSON string.
|
2019-11-17 21:26:43 +08:00
|
|
|
*/
|
2023-06-14 20:30:14 +08:00
|
|
|
public function toResponse($request): JsonResponse
|
2019-11-17 21:26:43 +08:00
|
|
|
{
|
2022-05-09 22:57:50 +08:00
|
|
|
$cleaned = mb_convert_encoding($this->data, 'UTF-8');
|
|
|
|
|
|
|
|
return response()->json($cleaned);
|
2019-11-17 21:26:43 +08:00
|
|
|
}
|
2021-03-08 06:24:05 +08:00
|
|
|
}
|