]> BookStack Code Mirror - bookstack/blob - app/Exceptions/Handler.php
Updated all application urls to allow path prefix.
[bookstack] / app / Exceptions / Handler.php
1 <?php
2
3 namespace BookStack\Exceptions;
4
5 use Exception;
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;
12
13 class Handler extends ExceptionHandler
14 {
15     /**
16      * A list of the exception types that should not be reported.
17      *
18      * @var array
19      */
20     protected $dontReport = [
21         AuthorizationException::class,
22         HttpException::class,
23         ModelNotFoundException::class,
24         ValidationException::class,
25     ];
26
27     /**
28      * Report or log an exception.
29      *
30      * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
31      *
32      * @param  \Exception $e
33      */
34     public function report(Exception $e)
35     {
36         return parent::report($e);
37     }
38
39     /**
40      * Render an exception into an HTTP response.
41      *
42      * @param  \Illuminate\Http\Request $request
43      * @param  \Exception $e
44      * @return \Illuminate\Http\Response
45      */
46     public function render($request, Exception $e)
47     {
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 redirect($e->redirectLocation);
53         }
54
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);
61         }
62
63         return parent::render($request, $e);
64     }
65 }