77use DisplayValidationException ;
88use AccountNotFoundException ;
99
10- use Illuminate \Database \Eloquent \ModelNotFoundException ;
11- use Symfony \Component \HttpKernel \Exception \HttpException ;
12- use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
13- use Illuminate \Auth \Access \AuthorizationException ;
14- use Illuminate \Foundation \Validation \ValidationException ;
15-
10+ use Illuminate \Auth \AuthenticationException ;
1611use Illuminate \Foundation \Exceptions \Handler as ExceptionHandler ;
1712
1813class Handler extends ExceptionHandler
@@ -23,10 +18,12 @@ class Handler extends ExceptionHandler
2318 * @var array
2419 */
2520 protected $ dontReport = [
26- HttpException::class,
27- ModelNotFoundException::class,
28- ValidationException::class,
29- AuthorizationException::class,
21+ \Illuminate \Auth \AuthenticationException::class,
22+ \Illuminate \Auth \Access \AuthorizationException::class,
23+ \Symfony \Component \HttpKernel \Exception \HttpException::class,
24+ \Illuminate \Database \Eloquent \ModelNotFoundException::class,
25+ \Illuminate \Session \TokenMismatchException::class,
26+ \Illuminate \Validation \ValidationException::class,
3027 ];
3128
3229 /**
@@ -37,9 +34,9 @@ class Handler extends ExceptionHandler
3734 * @param \Exception $e
3835 * @return void
3936 */
40- public function report (Exception $ e )
37+ public function report (Exception $ exception )
4138 {
42- return parent ::report ($ e );
39+ return parent ::report ($ exception );
4340 }
4441
4542 /**
@@ -83,4 +80,20 @@ public function render($request, Exception $e)
8380
8481 return parent ::render ($ request , $ e );
8582 }
83+
84+ /**
85+ * Convert an authentication exception into an unauthenticated response.
86+ *
87+ * @param \Illuminate\Http\Request $request
88+ * @param \Illuminate\Auth\AuthenticationException $exception
89+ * @return \Illuminate\Http\Response
90+ */
91+ protected function unauthenticated ($ request , AuthenticationException $ exception )
92+ {
93+ if ($ request ->expectsJson ()) {
94+ return response ()->json (['error ' => 'Unauthenticated. ' ], 401 );
95+ }
96+ return redirect ()->guest ('/auth/login ' );
97+ }
98+
8699}
0 commit comments