Handler.php 1.5KB

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