Handler.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Exceptions;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
  5. use Illuminate\Validation\ValidationException;
  6. use Throwable;
  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. 'current_password',
  24. 'password',
  25. 'password_confirmation',
  26. ];
  27. /**
  28. * Register the exception handling callbacks for the application.
  29. *
  30. * @return void
  31. */
  32. public function register()
  33. {
  34. $this->reportable(function (Throwable $e) {
  35. //
  36. });
  37. }
  38. public function render($request, Throwable $exception)
  39. {
  40. if ($exception instanceof ValidationException) {
  41. return response()->json([
  42. 'code' => 422,
  43. 'msg' => '调用参数错误',
  44. 'data' => $exception->errors()->first(),
  45. ], 422);
  46. }
  47. return parent::render($request, $exception);
  48. }
  49. }