Handler.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /*
  3. * This file is part of the Jiannei/lumen-api-starter.
  4. *
  5. * (c) Jiannei <longjian.huang@foxmail.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace App\Exceptions;
  11. use Exception;
  12. use Illuminate\Auth\Access\AuthorizationException;
  13. use Illuminate\Database\Eloquent\ModelNotFoundException;
  14. use Illuminate\Http\Exceptions\HttpResponseException;
  15. use Illuminate\Http\JsonResponse;
  16. use Illuminate\Http\Request;
  17. use Illuminate\Http\Response;
  18. use Illuminate\Validation\ValidationException;
  19. use Jiannei\Response\Laravel\Support\Traits\ExceptionTrait;
  20. use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
  21. use Symfony\Component\HttpKernel\Exception\HttpException;
  22. use Throwable;
  23. class Handler extends ExceptionHandler
  24. {
  25. use ExceptionTrait;
  26. /**
  27. * A list of the exception types that should not be reported.
  28. *
  29. * @var array
  30. */
  31. protected $dontReport = [
  32. AuthorizationException::class,
  33. HttpException::class,
  34. ModelNotFoundException::class,
  35. ValidationException::class,
  36. HttpResponseException::class,
  37. ];
  38. /**
  39. * Report or log an exception.
  40. *
  41. * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
  42. *
  43. * @param Throwable $exception
  44. *
  45. * @throws Exception
  46. */
  47. public function report(Throwable $exception)
  48. {
  49. parent::report($exception);
  50. }
  51. /**
  52. * Render an exception into an HTTP response.
  53. *
  54. * @param Request $request
  55. * @param Throwable $exception
  56. *
  57. * @return Response|JsonResponse
  58. *
  59. * @throws Throwable
  60. */
  61. public function render($request, Throwable $exception)
  62. {
  63. return parent::render($request, $exception);
  64. }
  65. }