Handler.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Exceptions;
  3. use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
  4. use Inertia\Inertia;
  5. use Throwable;
  6. class Handler extends ExceptionHandler
  7. {
  8. /**
  9. * A list of the exception types that are not reported.
  10. *
  11. * @var array<int, class-string<Throwable>>
  12. */
  13. protected $dontReport = [
  14. //
  15. ];
  16. /**
  17. * A list of the inputs that are never flashed for validation exceptions.
  18. *
  19. * @var array<int, string>
  20. */
  21. protected $dontFlash = [
  22. 'current_password',
  23. 'password',
  24. 'password_confirmation'
  25. ];
  26. /**
  27. * Register the exception handling callbacks for the application.
  28. *
  29. * @return void
  30. */
  31. public function register()
  32. {
  33. $this->reportable(function (Throwable $e) {
  34. //
  35. });
  36. }
  37. /**
  38. * Prepare exception for rendering.
  39. *
  40. * @param \Throwable $e
  41. * @return \Throwable
  42. */
  43. public function render($request, Throwable $e)
  44. {
  45. $response = parent::render($request, $e);
  46. if (!app()->environment(['local', 'testing']) && in_array($response->status(), [500, 503, 404, 403])) {
  47. return inertia('error/Index', ['status' => $response->status()])
  48. ->toResponse($request)
  49. ->setStatusCode($response->status());
  50. } else if ($response->status() === 419) {
  51. return back()->with([
  52. 'message' => 'The page expired, please try again.'
  53. ]);
  54. }
  55. return $response;
  56. }
  57. }