Commit 672f0018 by 张富康

GlobalExceptionHandler 修改异常打印信息

1 parent 6df0c809
......@@ -55,7 +55,7 @@ public class GlobalExceptionHandler {
private String EXCEPTION_PUSH_URL;
@Value("${pushExceptionFlag: true}")
private Boolean pushExceptionFlag;
@Value("${excludeExceptions: org.springframework.web.servlet.resource.NoResourceFoundException}")
@Value("${excludeExceptions:}")
private List<String> excludeExceptionList;
@Resource
private Environment environment;
......@@ -144,18 +144,21 @@ public class GlobalExceptionHandler {
*/
@ExceptionHandler(Exception.class)
public ResponseEntity<R<?>> handleException(Exception e, HttpServletRequest request) {
log.error("系统异常: ", e);
excludeExceptionList.add("org.springframework.web.servlet.resource.NoResourceFoundException");
String typeName = e.getClass().getTypeName();
boolean checkException = ObjectUtil.isNotEmpty(excludeExceptionList) && excludeExceptionList.contains(typeName);
if (!checkException) {
log.error("系统异常: ", e);
}
ResponseEntity<R<?>> body = ResponseEntity
.status(HttpStatus.OK)
.body(R.restResult(null, ErrorCodeEnum.SYSTEM_ERROR.getCode(), ErrorCodeEnum.SYSTEM_ERROR.getMessage()));
if (!pushExceptionFlag || StrUtil.isNotBlank(environment.getProperty(LOCAL_DEBUG))) {
return body;
}
String typeName = e.getClass().getTypeName();
// 可以在nacos进行配置哪些异常不发送信息 哪些异常发送信息
// 判断异常类型是否在list中
excludeExceptionList.add("org.springframework.web.servlet.resource.NoResourceFoundException");
if (ObjectUtil.isNotEmpty(excludeExceptionList) && excludeExceptionList.contains(typeName)) {
if (checkException) {
return body;
}
ExceptionPushRequest exceptionPushRequest = new ExceptionPushRequest();
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!