mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-11-21 23:07:55 +00:00
7249d947ec
In all other exceptions, when a Response is supposed to be returned, the Responsable interface is used instead of render.
33 lines
749 B
PHP
33 lines
749 B
PHP
<?php
|
|
|
|
namespace BookStack\Exceptions;
|
|
|
|
use Exception;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Contracts\Support\Responsable;
|
|
|
|
class JsonDebugException extends Exception implements Responsable
|
|
{
|
|
protected array $data;
|
|
|
|
/**
|
|
* JsonDebugException constructor.
|
|
*/
|
|
public function __construct(array $data)
|
|
{
|
|
$this->data = $data;
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
public function toResponse($request): JsonResponse
|
|
{
|
|
$cleaned = mb_convert_encoding($this->data, 'UTF-8');
|
|
|
|
return response()->json($cleaned);
|
|
}
|
|
}
|