Handler.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. ResponseException::class
  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. * @throws Exception
  33. */
  34. public function report(Exception $exception)
  35. {
  36. parent::report($exception);
  37. }
  38. /**
  39. * Render an exception into an HTTP response.
  40. *
  41. * @param \Illuminate\Http\Request $request
  42. * @param \Exception $exception
  43. * @return \Illuminate\Http\Response
  44. */
  45. public function render($request, Exception $exception)
  46. {
  47. return parent::render($request, $exception);
  48. }
  49. /**
  50. * Convert an authentication exception into a response.
  51. *
  52. * @param \Illuminate\Http\Request $request
  53. * @param \Illuminate\Auth\AuthenticationException $exception
  54. * @return \Illuminate\Http\Response
  55. */
  56. protected function unauthenticated($request, AuthenticationException $exception)
  57. {
  58. $route_name='login';
  59. if (is_mobile_route()) {
  60. $route_name='mobile.login';
  61. } elseif (is_pad_route()) {
  62. $route_name='hardware.pad.login';
  63. } elseif (is_statistics_route()) {
  64. $route_name='statistics.login';
  65. }
  66. return $request->expectsJson()
  67. ? response()->json(['message' => $exception->getMessage()], 401)
  68. : redirect()->guest(route($route_name));
  69. }
  70. }