Handler.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Exceptions;
  3. use Exception;
  4. use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
  5. use Illuminate\Http\Exceptions\HttpResponseException;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Http\Response;
  8. use Symfony\Component\HttpKernel\Exception\HttpException;
  9. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  10. use Throwable;
  11. class Handler extends ExceptionHandler
  12. {
  13. /**
  14. * A list of the exception types that are not reported.
  15. *
  16. * @var array
  17. */
  18. protected $dontReport = [
  19. //
  20. ];
  21. /**
  22. * A list of the inputs that are never flashed for validation exceptions.
  23. *
  24. * @var array
  25. */
  26. protected $dontFlash = [
  27. 'password',
  28. 'password_confirmation',
  29. ];
  30. /**
  31. * Report or log an exception.
  32. *
  33. * @param Throwable $exception
  34. * @return void
  35. * @throws Exception
  36. */
  37. public function report(Throwable $exception)
  38. {
  39. parent::report($exception);
  40. }
  41. /**
  42. * Render an exception into an HTTP response.
  43. *
  44. * @param Request $request
  45. * @param Throwable $exception
  46. * @return Response
  47. * @throws Throwable
  48. */
  49. public function render($request, Throwable $exception)
  50. {
  51. if ($exception instanceof HttpException) {
  52. $code = $exception->getStatusCode();
  53. switch ($code){
  54. case 419:return response()->view('exception.login');
  55. case 404:return response()->view('exception.404');
  56. default: return response()->view('exception.default',compact('code'));
  57. }
  58. }
  59. return parent::render($request, $exception);
  60. }
  61. }