java中引入一个自己制作的springaop异常处理的包,返回一个实体类 引入之后debug发现方法跑了 但是返回的还是原生的错误 怎么回事求大佬执教
以下是aop异常处理的代码
@ControllerAdvice
public class ExceptionHandle {
private static final Logger LOGGER = LogManager.getLogger(ExceptionHandle.class);
public ExceptionHandle() {
}
@ExceptionHandler({Exception.class})
@ResponseBody
public ResultModel exceptionGet(Exception e, HttpServletResponse response) {
if (e instanceof DescribeException) {
DescribeException MyException = (DescribeException)e;
if (MyException.getCode() == 1002) {
response.setStatus(404);
}
return ResultTools.error(MyException.getCode(), MyException.getMessage());
} else if (!(e instanceof StringIndexOutOfBoundsException) && !(e instanceof MethodArgumentTypeMismatchException)) {
LOGGER.error("【系统异常】{}", e);
response.setStatus(500);
return ResultTools.error(ExceptionEnum.UNKNOW_ERROR);
} else {
return ResultTools.error(ExceptionEnum.ERROR_PARA);
}
}
}
很奇怪 如果不用jar包的形式引入 直接用源码 是可以返回实体类的
比如:{“code”:1005,“msg”:“未知错误”}
但是如果用jar包形式 就会显示这种原生错误
“timestamp”: “2019-07-01T04:13:20.605+0000”,
“status”: 500,
“error”: “Internal Server Error”,
“message”: “String index out of range: 27”,
“path”: “/data/thermo_history/v1/2”