Handler.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Exceptions;
  3. use Exception;
  4. use Illuminate\Auth\AuthenticationException;
  5. use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
  6. class Handler extends ExceptionHandler
  7. {
  8. /**
  9. * A list of the exception types that are not reported.
  10. *
  11. * @var array
  12. */
  13. protected $dontReport = [
  14. //
  15. ];
  16. /**
  17. * A list of the inputs that are never flashed for validation exceptions.
  18. *
  19. * @var array
  20. */
  21. protected $dontFlash = [
  22. 'password',
  23. 'password_confirmation',
  24. ];
  25. /**
  26. * Report or log an exception.
  27. *
  28. * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
  29. *
  30. * @param \Exception $exception
  31. * @return void
  32. */
  33. public function report(Exception $exception)
  34. {
  35. parent::report($exception);
  36. }
  37. /**
  38. * Render an exception into an HTTP response.
  39. *
  40. * @param \Illuminate\Http\Request $request
  41. * @param \Exception $exception
  42. * @return \Illuminate\Http\Response
  43. */
  44. public function render($request, Exception $exception)
  45. {
  46. return parent::render($request, $exception);
  47. }
  48. /**
  49. * 登录过期后的跳转地址
  50. * @param \Illuminate\Http\Request $request
  51. * @param AuthenticationException $exception
  52. * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
  53. */
  54. protected function unauthenticated($request, AuthenticationException $exception)
  55. {
  56. return $request->expectsJson()
  57. ? response()->json(['message' => $exception->getMessage()], 401)
  58. : redirect()->guest(route('admin.login'));
  59. }
  60. }