3 namespace BookStack\Exceptions;
6 use Illuminate\Contracts\Support\Responsable;
7 use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
9 class NotifyException extends Exception implements Responsable, HttpExceptionInterface
12 public string $redirectLocation;
13 protected int $status;
15 public function __construct(string $message, string $redirectLocation = '/', int $status = 500)
17 $this->message = $message;
18 $this->redirectLocation = $redirectLocation;
19 $this->status = $status;
21 parent::__construct();
25 * Get the desired HTTP status code for this exception.
27 public function getStatusCode(): int
33 * Get the desired HTTP headers for this exception.
35 public function getHeaders(): array
41 * Send the response for this type of exception.
45 public function toResponse($request)
47 $message = $this->getMessage();
49 // Front-end JSON handling. API-side handling managed via handler.
50 if ($request->wantsJson()) {
51 return response()->json(['error' => $message], $this->getStatusCode());
54 if (!empty($message)) {
55 session()->flash('error', $message);
58 return redirect($this->redirectLocation);