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