【更新】新增MyBatisSystemException异常拦截处理
This commit is contained in:
parent
99e8ff82cc
commit
62d6c38113
@ -68,6 +68,7 @@ public class ClientUser extends CommonEntity {
|
||||
/** 性别 */
|
||||
@ApiModelProperty(value = "性别", position = 8)
|
||||
@TableField(insertStrategy = FieldStrategy.IGNORED, updateStrategy = FieldStrategy.IGNORED)
|
||||
@Trans(type = TransType.DICTIONARY, key = "GENDER")
|
||||
private String gender;
|
||||
|
||||
/** 年龄 */
|
||||
|
@ -17,6 +17,8 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpStatus;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.exceptions.PersistenceException;
|
||||
import org.mybatis.spring.MyBatisSystemException;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
import org.springframework.validation.BindException;
|
||||
@ -113,6 +115,21 @@ public class GlobalExceptionUtil {
|
||||
|
||||
// 如果是SaToken相关异常,则由AuthExceptionUtil处理
|
||||
return AuthExceptionUtil.getCommonResult(e);
|
||||
} else if(e instanceof MyBatisSystemException) {
|
||||
|
||||
// 如果是MyBatisSystemException
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof PersistenceException) {
|
||||
Throwable secondCause = cause.getCause();
|
||||
if (secondCause instanceof CommonException) {
|
||||
CommonException commonException = (CommonException) secondCause;
|
||||
commonResult = CommonResult.get(commonException.getCode(), commonException.getMsg(), null);
|
||||
} else {
|
||||
commonResult = CommonResult.error("数据操作异常");
|
||||
}
|
||||
}else {
|
||||
commonResult = CommonResult.error("数据操作异常");
|
||||
}
|
||||
} else if (e instanceof CommonException) {
|
||||
|
||||
// 通用业务异常,直接返回给前端
|
||||
|
Loading…
x
Reference in New Issue
Block a user