Handler.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Exceptions;
  3. use Exception;
  4. use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
  5. class Handler extends ExceptionHandler
  6. {
  7. /**
  8. * A list of the exception types that should not be reported.
  9. *
  10. * @var array
  11. */
  12. protected $dontReport = [
  13. \Illuminate\Auth\AuthenticationException::class,
  14. \Illuminate\Auth\Access\AuthorizationException::class,
  15. \Symfony\Component\HttpKernel\Exception\HttpException::class,
  16. \Illuminate\Database\Eloquent\ModelNotFoundException::class,
  17. \Illuminate\Validation\ValidationException::class,
  18. ];
  19. /**
  20. * Report or log an exception.
  21. *
  22. * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
  23. *
  24. * @param \Exception $e
  25. * @return void
  26. */
  27. public function report(Exception $e)
  28. {
  29. parent::report($e);
  30. }
  31. /**
  32. * Render an exception into an HTTP response.
  33. *
  34. * @param \Illuminate\Http\Request $request
  35. * @param \Exception $e
  36. * @return \Illuminate\Http\Response
  37. */
  38. public function render($request, Exception $e)
  39. {
  40. return parent::render($request, $e);
  41. }
  42. /**
  43. * Convert an authentication exception into an unauthenticated response.
  44. *
  45. * @param \Illuminate\Http\Request $request
  46. * @param \Illuminate\Auth\AuthenticationException $e
  47. * @return \Illuminate\Http\Response
  48. */
  49. protected function unauthenticated($request, AuthenticationException $e)
  50. {
  51. if ($request->expectsJson()) {
  52. return response()->json(['error' => 'Unauthenticated.'], 401);
  53. } else {
  54. return redirect()->guest('login');
  55. }
  56. }
  57. }