3 namespace BookStack\Exceptions;
6 use Illuminate\Contracts\Validation\ValidationException;
7 use Illuminate\Database\Eloquent\ModelNotFoundException;
8 use PhpSpec\Exception\Example\ErrorException;
9 use Symfony\Component\HttpKernel\Exception\HttpException;
10 use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
11 use Illuminate\Auth\Access\AuthorizationException;
13 class Handler extends ExceptionHandler
16 * A list of the exception types that should not be reported.
20 protected $dontReport = [
21 AuthorizationException::class,
23 ModelNotFoundException::class,
24 ValidationException::class,
28 * Report or log an exception.
30 * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
32 * @param \Exception $e
34 public function report(Exception $e)
36 return parent::report($e);
40 * Render an exception into an HTTP response.
42 * @param \Illuminate\Http\Request $request
43 * @param \Exception $e
44 * @return \Illuminate\Http\Response
46 public function render($request, Exception $e)
48 // Handle notify exceptions which will redirect to the
49 // specified location then show a notification message.
50 if ($e instanceof NotifyException) {
51 \Session::flash('error', $e->message);
52 return response()->redirectTo($e->redirectLocation);
55 // Handle pretty exceptions which will show a friendly application-fitting page
56 // Which will include the basic message to point the user roughly to the cause.
57 if (($e instanceof PrettyException || $e->getPrevious() instanceof PrettyException) && !config('app.debug')) {
58 $message = ($e instanceof PrettyException) ? $e->getMessage() : $e->getPrevious()->getMessage();
59 $code = ($e->getCode() === 0) ? 500 : $e->getCode();
60 return response()->view('errors/' . $code, ['message' => $message], $code);
63 return parent::render($request, $e);