Handler.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. \Illuminate\Auth\AuthenticationException::class,
  15. \Illuminate\Auth\Access\AuthorizationException::class,
  16. \Symfony\Component\HttpKernel\Exception\HttpException::class,
  17. \Illuminate\Database\Eloquent\ModelNotFoundException::class,
  18. \Illuminate\Validation\ValidationException::class,
  19. ];
  20. /**
  21. * Report or log an exception.
  22. *
  23. * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
  24. *
  25. * @param \Exception $exception
  26. * @return void
  27. */
  28. public function report(Exception $exception)
  29. {
  30. parent::report($exception);
  31. }
  32. /**
  33. * Render an exception into an HTTP response.
  34. *
  35. * @param \Illuminate\Http\Request $request
  36. * @param \Exception $exception
  37. * @return \Illuminate\Http\Response
  38. */
  39. public function render($request, Exception $exception)
  40. {
  41. return parent::render($request, $exception);
  42. }
  43. /**
  44. * Convert an authentication exception into an unauthenticated response.
  45. *
  46. * @param \Illuminate\Http\Request $request
  47. * @param \Illuminate\Auth\AuthenticationException $exception
  48. * @return \Illuminate\Http\Response
  49. */
  50. protected function unauthenticated($request, AuthenticationException $exception)
  51. {
  52. if ($request->expectsJson()) {
  53. return response()->json(['error' => 'Unauthenticated.'], 401);
  54. }
  55. return redirect()->guest('login');
  56. }
  57. }