Handler.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace App\Exceptions;
  3. use Exception;
  4. use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
  5. use Illuminate\Support\Facades\Log;
  6. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  7. class Handler extends ExceptionHandler
  8. {
  9. /**
  10. * A list of the exception types that are not reported.
  11. *
  12. * @var array
  13. */
  14. protected $dontReport = [
  15. //
  16. ];
  17. /**
  18. * A list of the inputs that are never flashed for validation exceptions.
  19. *
  20. * @var array
  21. */
  22. protected $dontFlash = [
  23. 'password',
  24. 'password_confirmation',
  25. ];
  26. /**
  27. * Report or log an exception.
  28. *
  29. * @param \Exception $exception
  30. * @return void
  31. */
  32. public function report(Exception $exception)
  33. {
  34. parent::report($exception);
  35. }
  36. /**
  37. * Render an exception into an HTTP response.
  38. *
  39. * @param \Illuminate\Http\Request $request
  40. * @param \Exception $exception
  41. * @return \Illuminate\Http\Response
  42. */
  43. public function render($request, Exception $exception)
  44. {
  45. if ($exception instanceof NotFoundHttpException) {
  46. $code = $exception->getStatusCode();
  47. if (view()->exists('errors.' . $code)) {
  48. return response()->view('errors.' . $exception->getStatusCode(), ['message' => $exception->getMessage()], 404);
  49. }
  50. }
  51. return parent::render($request, $exception);
  52. }
  53. }