15
15
use Illuminate \Session \TokenMismatchException ;
16
16
use Illuminate \Support \Arr ;
17
17
use Illuminate \Support \Facades \Auth ;
18
+ use Illuminate \Support \Facades \Log ;
18
19
use Illuminate \Support \Reflector ;
19
20
use Illuminate \Support \Traits \ReflectsClosures ;
20
21
use Illuminate \Support \ViewErrorBag ;
@@ -81,16 +82,10 @@ class ExceptionHandler implements ExceptionHandlerContract
81
82
* @var string[]
82
83
*/
83
84
protected $ internalDontReport = [
84
- AuthenticationException::class,
85
- AuthorizationException::class,
86
85
HttpException::class,
87
86
HttpResponseException::class,
88
- ModelNotFoundException::class,
89
- MultipleRecordsFoundException::class,
90
- RecordsNotFoundException::class,
91
87
SuspiciousOperationException::class,
92
88
TokenMismatchException::class,
93
- ValidationException::class,
94
89
];
95
90
96
91
/**
@@ -234,20 +229,16 @@ public function report(Throwable $e)
234
229
}
235
230
}
236
231
237
- try {
238
- $ logger = $ this ->container ->make (LoggerInterface::class);
239
- } catch (Exception $ ex ) {
240
- throw $ e ;
241
- }
242
232
243
- $ logger -> error (
233
+ Log:: error (
244
234
$ e ->getMessage (),
245
235
array_merge (
246
236
$ this ->exceptionContext ($ e ),
247
237
$ this ->context (),
248
238
['exception ' => $ e ]
249
239
)
250
240
);
241
+
251
242
}
252
243
253
244
/**
@@ -300,8 +291,7 @@ protected function context()
300
291
{
301
292
try {
302
293
return array_filter ([
303
- 'userId ' => Auth::id (),
304
- // 'email' => optional(Auth::user())->email,
294
+
305
295
]);
306
296
} catch (Throwable $ e ) {
307
297
return [];
@@ -341,10 +331,6 @@ public function render($request, Throwable $e)
341
331
342
332
if ($ e instanceof HttpResponseException) {
343
333
return $ e ->getResponse ();
344
- } elseif ($ e instanceof AuthenticationException) {
345
- return $ this ->unauthenticated ($ request , $ e );
346
- } elseif ($ e instanceof ValidationException) {
347
- return $ this ->convertValidationExceptionToResponse ($ e , $ request );
348
334
}
349
335
350
336
return $ this ->shouldReturnJson ($ request , $ e )
@@ -377,82 +363,10 @@ protected function mapException(Throwable $e)
377
363
*/
378
364
protected function prepareException (Throwable $ e )
379
365
{
380
- if ($ e instanceof ModelNotFoundException) {
381
- $ e = new NotFoundHttpException ($ e ->getMessage (), $ e );
382
- } elseif ($ e instanceof AuthorizationException) {
383
- $ e = new AccessDeniedHttpException ($ e ->getMessage (), $ e );
384
- } elseif ($ e instanceof TokenMismatchException) {
385
- $ e = new HttpException (419 , $ e ->getMessage (), $ e );
386
- } elseif ($ e instanceof SuspiciousOperationException) {
387
- $ e = new NotFoundHttpException ('Bad hostname provided. ' , $ e );
388
- } elseif ($ e instanceof RecordsNotFoundException) {
389
- $ e = new NotFoundHttpException ('Not found. ' , $ e );
390
- }
391
366
392
367
return $ e ;
393
368
}
394
369
395
- /**
396
- * Convert an authentication exception into a response.
397
- *
398
- * @param \Illuminate\Http\Request $request
399
- * @param \Illuminate\Auth\AuthenticationException $exception
400
- * @return \Symfony\Component\HttpFoundation\Response
401
- */
402
- protected function unauthenticated ($ request , AuthenticationException $ exception )
403
- {
404
- return $ this ->shouldReturnJson ($ request , $ exception )
405
- ? response ()->json (['message ' => $ exception ->getMessage ()], 401 )
406
- : redirect ()->guest ($ exception ->redirectTo () ?? route ('login ' ));
407
- }
408
-
409
- /**
410
- * Create a response object from the given validation exception.
411
- *
412
- * @param \Illuminate\Validation\ValidationException $e
413
- * @param \Illuminate\Http\Request $request
414
- * @return \Symfony\Component\HttpFoundation\Response
415
- */
416
- protected function convertValidationExceptionToResponse (ValidationException $ e , $ request )
417
- {
418
- if ($ e ->response ) {
419
- return $ e ->response ;
420
- }
421
-
422
- return $ this ->shouldReturnJson ($ request , $ e )
423
- ? $ this ->invalidJson ($ request , $ e )
424
- : $ this ->invalid ($ request , $ e );
425
- }
426
-
427
- /**
428
- * Convert a validation exception into a response.
429
- *
430
- * @param \Illuminate\Http\Request $request
431
- * @param \Illuminate\Validation\ValidationException $exception
432
- * @return \Illuminate\Http\Response
433
- */
434
- protected function invalid ($ request , ValidationException $ exception )
435
- {
436
- return redirect ($ exception ->redirectTo ?? url ()->previous ())
437
- ->withInput (Arr::except ($ request ->input (), $ this ->dontFlash ))
438
- ->withErrors ($ exception ->errors (), $ request ->input ('_error_bag ' , $ exception ->errorBag ));
439
- }
440
-
441
- /**
442
- * Convert a validation exception into a JSON response.
443
- *
444
- * @param \Illuminate\Http\Request $request
445
- * @param \Illuminate\Validation\ValidationException $exception
446
- * @return \Illuminate\Http\JsonResponse
447
- */
448
- protected function invalidJson ($ request , ValidationException $ exception )
449
- {
450
- return response ()->json ([
451
- 'message ' => $ exception ->getMessage (),
452
- 'errors ' => $ exception ->errors (),
453
- ], $ exception ->status );
454
- }
455
-
456
370
/**
457
371
* Determine if the exception handler response should be JSON.
458
372
*
@@ -573,16 +487,13 @@ protected function renderExceptionWithSymfony(Throwable $e, $debug)
573
487
*/
574
488
protected function renderHttpException (HttpExceptionInterface $ e )
575
489
{
576
- //$this->registerErrorViewPaths();
577
490
578
- if ( view ()-> exists ( $ view = $ this -> getHttpExceptionView ( $ e ))) {
579
- return response ()-> view ( $ view , [
580
- ' errors ' => new ViewErrorBag (),
581
- ' exception ' => $ e ,
582
- ], $ e -> getStatusCode (), $ e -> getHeaders () );
491
+ try {
492
+ $ view = $ this -> getHttpExceptionView ( $ e );
493
+ return app ()-> make (Template::class)-> display ( $ view , " error " , $ e -> getStatusCode ());
494
+ } catch ( Throwable $ e ){
495
+ return $ this -> convertExceptionToResponse ( $ e );
583
496
}
584
-
585
- return $ this ->convertExceptionToResponse ($ e );
586
497
}
587
498
588
499
/**
@@ -592,7 +503,7 @@ protected function renderHttpException(HttpExceptionInterface $e)
592
503
*/
593
504
protected function registerErrorViewPaths ()
594
505
{
595
- ( new RegisterErrorViewPaths ())();
506
+
596
507
}
597
508
598
509
/**
@@ -603,7 +514,7 @@ protected function registerErrorViewPaths()
603
514
*/
604
515
protected function getHttpExceptionView (HttpExceptionInterface $ e )
605
516
{
606
- return "error/ error {$ e ->getStatusCode ()}" ;
517
+ return "errors. error {$ e ->getStatusCode ()}" ;
607
518
}
608
519
609
520
/**
0 commit comments