Commit ee3e507f07f4284dfbcf09dd222fca9c03228a64

Authored by YunaiV
1 parent 88ac5be8

【优化】GlobalExceptionHandler 新增 IGNORE_ERROR_MESSAGES,用于忽略“无效的刷新令牌”等非关键提示

yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java
... ... @@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil;
6 6 import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService;
7 7 import cn.iocoder.yudao.framework.common.exception.ServiceException;
8 8 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  9 +import cn.iocoder.yudao.framework.common.util.collection.SetUtils;
9 10 import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
10 11 import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils;
11 12 import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
... ... @@ -32,6 +33,7 @@ import org.springframework.web.servlet.NoHandlerFoundException;
32 33  
33 34 import java.time.LocalDateTime;
34 35 import java.util.Map;
  36 +import java.util.Set;
35 37  
36 38 import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.*;
37 39  
... ... @@ -45,6 +47,11 @@ import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeC
45 47 @Slf4j
46 48 public class GlobalExceptionHandler {
47 49  
  50 + /**
  51 + * 忽略的 ServiceException 错误提示,避免打印过多 logger
  52 + */
  53 + public static final Set<String> IGNORE_ERROR_MESSAGES = SetUtils.asSet("无效的刷新令牌");
  54 +
48 55 @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
49 56 private final String applicationName;
50 57  
... ... @@ -199,7 +206,10 @@ public class GlobalExceptionHandler {
199 206 */
200 207 @ExceptionHandler(value = ServiceException.class)
201 208 public CommonResult<?> serviceExceptionHandler(ServiceException ex) {
202   - log.info("[serviceExceptionHandler]", ex);
  209 + if (!IGNORE_ERROR_MESSAGES.contains(ex.getMessage())) {
  210 + // 不包含的时候,才进行打印,避免 ex 堆栈过多
  211 + log.info("[serviceExceptionHandler]", ex);
  212 + }
203 213 return CommonResult.error(ex.getCode(), ex.getMessage());
204 214 }
205 215  
... ...