1 | <?php |
||
2 | |||
3 | namespace App\Exceptions; |
||
4 | |||
5 | use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; |
||
6 | |||
7 | class Handler extends ExceptionHandler |
||
8 | { |
||
9 | /** |
||
10 | * A list of the exception types that are not reported. |
||
11 | * |
||
12 | * @var array |
||
13 | */ |
||
14 | protected $dontReport = [ |
||
15 | // |
||
16 | ]; |
||
17 | |||
18 | /** |
||
19 | * A list of the inputs that are never flashed for validation exceptions. |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $dontFlash = [ |
||
24 | 'password', |
||
25 | 'password_confirmation', |
||
26 | ]; |
||
27 | |||
28 | /** |
||
29 | * Catch errors with Sentry. |
||
30 | */ |
||
31 | public function register(): void |
||
32 | { |
||
33 | $this->reportable(function (Throwable $e) { |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
34 | if (app()->bound('sentry')) { |
||
35 | app('sentry')->captureException($e); |
||
36 | } |
||
37 | }); |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * Report or log an exception. |
||
42 | * |
||
43 | * |
||
44 | * @return void |
||
45 | * |
||
46 | * @throws \Throwable |
||
47 | */ |
||
48 | public function report(\Throwable $exception) |
||
49 | { |
||
50 | parent::report($exception); |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * @param \Illuminate\Http\Request $request |
||
55 | * @return \Illuminate\Http\RedirectResponse|\Symfony\Component\HttpFoundation\Response |
||
56 | * |
||
57 | * @throws \Throwable |
||
58 | */ |
||
59 | public function render($request, \Throwable $exception) |
||
60 | { |
||
61 | if ($exception instanceof \Spatie\Permission\Exceptions\UnauthorizedException) { |
||
62 | abort(401); |
||
63 | } |
||
64 | if ($exception instanceof \Illuminate\Session\TokenMismatchException) { |
||
65 | return redirect() |
||
66 | ->back() |
||
67 | ->withInput($request->except(['password', 'password_confirmation'])) |
||
68 | ->with('error', 'The form has expired due to inactivity. Please refresh the page and try again'); |
||
69 | } |
||
70 | |||
71 | return parent::render($request, $exception); |
||
72 | } |
||
73 | } |
||
74 |