X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/b8e2d75014c89c9e345c3f940ec8743bd158df67..refs/pull/5280/head:/app/Exceptions/NotifyException.php diff --git a/app/Exceptions/NotifyException.php b/app/Exceptions/NotifyException.php index 4f8105960..b62b8fde6 100644 --- a/app/Exceptions/NotifyException.php +++ b/app/Exceptions/NotifyException.php @@ -1,18 +1,60 @@ -message = $message; $this->redirectLocation = $redirectLocation; + $this->status = $status; + parent::__construct(); } + + /** + * Get the desired HTTP status code for this exception. + */ + public function getStatusCode(): int + { + return $this->status; + } + + /** + * Get the desired HTTP headers for this exception. + */ + public function getHeaders(): array + { + return []; + } + + /** + * Send the response for this type of exception. + * + * {@inheritdoc} + */ + public function toResponse($request) + { + $message = $this->getMessage(); + + // Front-end JSON handling. API-side handling managed via handler. + if ($request->wantsJson()) { + return response()->json(['error' => $message], $this->getStatusCode()); + } + + if (!empty($message)) { + session()->flash('error', $message); + } + + return redirect($this->redirectLocation); + } }