Handler.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 should not be reported.
  10. *
  11. * @var array
  12. */
  13. protected $dontReport = [
  14. //
  15. ];
  16. /**
  17. * Report or log an exception.
  18. *
  19. * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
  20. *
  21. * @param \Exception $exception
  22. * @return void
  23. */
  24. public function report(Exception $exception)
  25. {
  26. parent::report($exception);
  27. }
  28. /**
  29. * Render an exception into an HTTP response.
  30. *
  31. * @param \Illuminate\Http\Request $request
  32. * @param \Exception $exception
  33. * @return \Illuminate\Http\Response
  34. */
  35. public function render($request, Exception $exception)
  36. {
  37. return parent::render($request, $exception);
  38. }
  39. /**
  40. * Convert an authentication exception into an unauthenticated response.
  41. *
  42. * @param \Illuminate\Http\Request $request
  43. * @param \Illuminate\Auth\AuthenticationException $exception
  44. * @return \Illuminate\Http\Response
  45. */
  46. protected function unauthenticated($request, AuthenticationException $exception)
  47. {
  48. return $request->expectsJson()
  49. ? response()->json(['error' => 'Unauthenticated.'], 401)
  50. : redirect()->guest(route('login'));
  51. }
  52. }