Handler.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. * @param \Exception $exception
  29. * @return void
  30. */
  31. public function report(Exception $exception)
  32. {
  33. parent::report($exception);
  34. }
  35. /**
  36. * Render an exception into an HTTP response.
  37. *
  38. * @param \Illuminate\Http\Request $request
  39. * @param \Exception $exception
  40. * @return \Illuminate\Http\Response
  41. */
  42. public function render($request, Exception $exception)
  43. {
  44. return parent::render($request, $exception);
  45. }
  46. protected function unauthenticated($request, AuthenticationException $exception)
  47. {
  48. return $request->expectsJson()
  49. ? response()->json(['code'=>401,'message' => '您还未登录,需要登录后才能进行该操作'], 200)
  50. : redirect()->guest(route('auth.user.login'));
  51. }
  52. }