Commit 672f0018 by 张富康

GlobalExceptionHandler 修改异常打印信息

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