fix(web): 修复全局异常处理器并更新版本号
- 添加 ValidationException 异常处理支持 - 扩展异常处理器以捕获 RuntimeException - 为 BindException 添加文档注释 - 新增 ValidationException 专门处理方法 - 更新父项目及所有子模块版本从 1.5.2 到 1.5.3
This commit is contained in:
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>vip.jcfd</groupId>
|
||||
<artifactId>zkh-framework</artifactId>
|
||||
<version>1.5.2</version>
|
||||
<version>1.5.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>zkh-web</artifactId>
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package vip.jcfd.web.config;
|
||||
|
||||
import jakarta.validation.ValidationException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.validation.BindException;
|
||||
@ -18,8 +19,8 @@ public class GlobalExceptionHandler {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
|
||||
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
public R<String> handleException(Exception e) {
|
||||
@ExceptionHandler(value = {Exception.class, RuntimeException.class})
|
||||
public R<String> handleException(Throwable e) {
|
||||
log.error("服务异常", e);
|
||||
return R.serverError("服务器繁忙,请稍候重试");
|
||||
}
|
||||
@ -37,6 +38,9 @@ public class GlobalExceptionHandler {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles bind exceptions; logs and returns formatted field errors
|
||||
*/
|
||||
@ExceptionHandler(value = BindException.class)
|
||||
public R<String> handleBindException(BindException e) {
|
||||
log.error("接口入参校验失败", e);
|
||||
@ -44,4 +48,10 @@ public class GlobalExceptionHandler {
|
||||
List<FieldError> fieldErrors = e.getBindingResult().getFieldErrors();
|
||||
return R.error(String.join("。\n", fieldErrors.stream().map(FieldError::getDefaultMessage).toList()));
|
||||
}
|
||||
|
||||
@ExceptionHandler(value = ValidationException.class)
|
||||
public R<String> handleValidationException(ValidationException e) {
|
||||
log.error("接口入参校验失败", e);
|
||||
return R.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user