diff --git a/app/ExceptionHandle.php b/app/ExceptionHandle.php index 453d126..1c1f437 100644 --- a/app/ExceptionHandle.php +++ b/app/ExceptionHandle.php @@ -51,6 +51,12 @@ class ExceptionHandle extends Handle public function render($request, Throwable $e): Response { // 添加自定义异常处理机制 + if ($e instanceof ValidateException) { + return json(['code'=>400,'message'=>$e->getMessage()]); + } + if ($request->isJson()) { + return json(['code'=>400,'message'=>$e->getMessage()]); + } // 其他错误交给系统处理 return parent::render($request, $e);