|
|
|
@ -4,6 +4,8 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import cn.stylefeng.roses.kernel.auth.api.exception.AuthException;
|
|
|
|
|
import cn.stylefeng.roses.kernel.auth.api.exception.enums.AuthExceptionEnum;
|
|
|
|
|
import cn.stylefeng.roses.kernel.demo.exception.DemoException;
|
|
|
|
|
import cn.stylefeng.roses.kernel.demo.exception.enums.DemoExceptionEnum;
|
|
|
|
|
import cn.stylefeng.roses.kernel.rule.constants.SymbolConstant;
|
|
|
|
|
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
|
|
|
|
|
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
|
|
|
|
@ -16,6 +18,8 @@ import cn.stylefeng.roses.kernel.rule.util.ResponseRenderUtil;
|
|
|
|
|
import cn.stylefeng.roses.kernel.validator.api.exception.ParamValidateException;
|
|
|
|
|
import cn.stylefeng.roses.kernel.validator.api.exception.enums.ValidatorExceptionEnum;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.ibatis.exceptions.PersistenceException;
|
|
|
|
|
import org.mybatis.spring.MyBatisSystemException;
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
import org.springframework.http.converter.HttpMessageNotReadableException;
|
|
|
|
|
import org.springframework.ui.Model;
|
|
|
|
@ -227,6 +231,28 @@ public class GlobalExceptionHandler {
|
|
|
|
|
return renderJson(e.getErrorCode(), e.getUserTip(), e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 拦截mybatis数据库操作的异常
|
|
|
|
|
* <p>
|
|
|
|
|
* 用在demo模式,拦截DemoException
|
|
|
|
|
*
|
|
|
|
|
* @author stylefeng
|
|
|
|
|
* @date 2020/5/5 15:19
|
|
|
|
|
*/
|
|
|
|
|
@ExceptionHandler(MyBatisSystemException.class)
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public ErrorResponseData persistenceException(MyBatisSystemException e) {
|
|
|
|
|
log.error(">>> mybatis操作出现异常,具体信息为:{}", e.getMessage());
|
|
|
|
|
Throwable cause = e.getCause();
|
|
|
|
|
if (cause instanceof PersistenceException) {
|
|
|
|
|
Throwable secondCause = cause.getCause();
|
|
|
|
|
if (secondCause instanceof DemoException) {
|
|
|
|
|
return renderJson(DemoExceptionEnum.DEMO_OPERATE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return renderJson(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 拦截未知的运行时异常
|
|
|
|
|
*
|
|
|
|
|