Handler.php 1.8 KB

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