Handler.php 1.7 KB

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