Handler.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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
  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. \Zttp\ConnectionException::class,
  17. \GuzzleHttp\Exception\ConnectException::class,
  18. \Illuminate\Http\Client\ConnectionException::class
  19. ];
  20. /**
  21. * A list of the inputs that are never flashed for validation exceptions.
  22. *
  23. * @var array
  24. */
  25. protected $dontFlash = [
  26. 'password',
  27. 'password_confirmation',
  28. ];
  29. /**
  30. * Report or log an exception.
  31. *
  32. * @param \Exception $exception
  33. *
  34. * @return void
  35. */
  36. public function report(Throwable $exception)
  37. {
  38. parent::report($exception);
  39. }
  40. /**
  41. * Register the exception handling callbacks for the application.
  42. *
  43. * @return void
  44. */
  45. public function register()
  46. {
  47. $this->reportable(function (\BadMethodCallException $e) {
  48. return app()->environment() !== 'production';
  49. });
  50. $this->reportable(function (\Illuminate\Http\Client\ConnectionException $e) {
  51. return app()->environment() !== 'production';
  52. });
  53. }
  54. /**
  55. * Render an exception into an HTTP response.
  56. *
  57. * @param \Illuminate\Http\Request $request
  58. * @param \Exception $exception
  59. *
  60. * @return \Illuminate\Http\Response
  61. */
  62. public function render($request, Throwable $exception)
  63. {
  64. if ($request->wantsJson())
  65. return response()->json(
  66. ['error' => $exception->getMessage()],
  67. method_exists($exception, 'getStatusCode') ? $exception->getStatusCode() : 500
  68. );
  69. return parent::render($request, $exception);
  70. }
  71. }