Handler.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Exceptions;
  3. use Exception;
  4. use Illuminate\Database\Eloquent\ModelNotFoundException;
  5. use Symfony\Component\HttpKernel\Exception\HttpException;
  6. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  7. use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
  8. class Handler extends ExceptionHandler
  9. {
  10. /**
  11. * A list of the exception types that should not be reported.
  12. *
  13. * @var array
  14. */
  15. protected $dontReport = [
  16. HttpException::class,
  17. ModelNotFoundException::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. return 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. if ($e instanceof ModelNotFoundException) {
  41. $e = new NotFoundHttpException($e->getMessage(), $e);
  42. }
  43. return parent::render($request, $e);
  44. }
  45. }