Total Complexity | 12 |
Total Lines | 143 |
Duplicated Lines | 0 % |
Coverage | 81.82% |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
16 | class Handler extends ExceptionHandler |
||
17 | { |
||
18 | /** |
||
19 | * A list of the exception types that are not reported. |
||
20 | * |
||
21 | * @var array |
||
|
|||
22 | */ |
||
23 | protected $dontReport = []; |
||
24 | |||
25 | /** |
||
26 | * A list of the inputs that are never flashed for validation exceptions. |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $dontFlash = [ |
||
31 | 'password', |
||
32 | 'password_confirmation', |
||
33 | 'current_password', |
||
34 | 'new_password', |
||
35 | 'new_password_confirmation', |
||
36 | ]; |
||
37 | |||
38 | /** |
||
39 | * OVERRIDE |
||
40 | * A list of the internal exception types that should not be reported. |
||
41 | 11 | * |
|
42 | * @var array |
||
43 | 11 | */ |
|
44 | 11 | protected $internalDontReport = [ |
|
45 | AuthenticationException::class, |
||
46 | AuthorizationException::class, |
||
47 | HttpException::class, |
||
48 | HttpResponseException::class, |
||
49 | ModelNotFoundException::class, |
||
50 | SuspiciousOperationException::class, |
||
51 | // TokenMismatchException::class, |
||
52 | ValidationException::class, |
||
53 | 11 | ]; |
|
54 | |||
55 | 11 | /** |
|
56 | * Report or log an exception. |
||
57 | * |
||
58 | 11 | * @param \Exception $exception |
|
2 ignored issues
–
show
|
|||
59 | * @return void |
||
60 | */ |
||
61 | public function report(Exception $exception) |
||
62 | { |
||
63 | if ($exception instanceof TokenMismatchException) { |
||
64 | $logData = [ |
||
65 | 'requestToken' => request()->header('x-csrf-token'), |
||
66 | 'sessionToken' => session()->token(), |
||
67 | 'session' => session()->all(), |
||
68 | 1 | 'user' => request()->user(), |
|
69 | 'requestUrl' => request()->url() |
||
70 | 1 | ]; |
|
71 | $message = '419 CSRF Token Mismatch. ' . collect($logData)->toJson(); |
||
72 | Log::debug($message); |
||
73 | 1 | } |
|
74 | |||
75 | parent::report($exception); |
||
76 | 1 | } |
|
77 | |||
78 | 1 | /** |
|
79 | * OVERRIDE |
||
80 | * Get the default context variables for logging. |
||
81 | * |
||
82 | * @return array |
||
83 | */ |
||
84 | protected function context() |
||
96 | } |
||
97 | } |
||
98 | 2 | ||
99 | /** |
||
100 | * Render an exception into an HTTP response. |
||
101 | * |
||
102 | * @param \Illuminate\Http\Request $request |
||
2 ignored issues
–
show
|
|||
103 | * @param \Exception $exception |
||
2 ignored issues
–
show
|
|||
104 | * @return \Illuminate\Http\Response |
||
105 | */ |
||
106 | public function render($request, Exception $exception) |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * Convert an authentication exception into an unauthenticated response. |
||
121 | * |
||
122 | * @param \Illuminate\Http\Request $request |
||
2 ignored issues
–
show
|
|||
123 | * @param \Illuminate\Auth\AuthenticationException $exception |
||
2 ignored issues
–
show
|
|||
124 | * @return \Illuminate\Http\Response |
||
125 | */ |
||
126 | protected function unauthenticated($request, AuthenticationException $exception) |
||
137 | } |
||
138 | |||
139 | /** |
||
140 | * OVERRIDE |
||
141 | * Render the given HttpException. |
||
142 | * |
||
143 | * @param \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface $e |
||
2 ignored issues
–
show
|
|||
144 | * @return \Symfony\Component\HttpFoundation\Response |
||
145 | */ |
||
146 | protected function renderHttpException(HttpExceptionInterface $e) |
||
147 | { |
||
148 | if (!view()->exists("errors.{$e->getStatusCode()}")) { |
||
149 | return response()->view('errors.default', [ |
||
150 | 'exception' => $e, |
||
151 | 'goc' => Lang::get('common/goc'), |
||
152 | 'alert' => Lang::get('common/alert'), |
||
153 | 'error' => [ |
||
154 | 'title' => 'Error' |
||
155 | ] |
||
156 | ], $e->getStatusCode(), $e->getHeaders()); |
||
157 | } |
||
158 | return parent::renderHttpException($e); |
||
159 | } |
||
161 |