Handler.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace App\Exceptions;
  3. use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
  4. use Throwable;
  5. use League\OAuth2\Server\Exception\OAuthServerException;
  6. use Zttp\ConnectionException;
  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. OAuthServerException::class,
  16. ConnectionException::class
  17. ];
  18. /**
  19. * A list of the inputs that are never flashed for validation exceptions.
  20. *
  21. * @var array
  22. */
  23. protected $dontFlash = [
  24. 'password',
  25. 'password_confirmation',
  26. ];
  27. /**
  28. * Report or log an exception.
  29. *
  30. * @param \Exception $exception
  31. *
  32. * @return void
  33. */
  34. public function report(Throwable $exception)
  35. {
  36. parent::report($exception);
  37. }
  38. /**
  39. * Render an exception into an HTTP response.
  40. *
  41. * @param \Illuminate\Http\Request $request
  42. * @param \Exception $exception
  43. *
  44. * @return \Illuminate\Http\Response
  45. */
  46. public function render($request, Throwable $exception)
  47. {
  48. if ($request->wantsJson())
  49. return response()->json(
  50. ['error' => $exception->getMessage()],
  51. method_exists($exception, 'getStatusCode') ? $exception->getStatusCode() : 500
  52. );
  53. return parent::render($request, $exception);
  54. }
  55. }