From 6fc6fb1bc808c9e6e27d6372bd804dfc22a70058 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 3 May 2024 09:53:00 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91GlobalExcep?= =?UTF-8?q?tionHandler=20=E6=96=B0=E5=A2=9E=20IGNORE=5FERROR=5FMESSAGES?= =?UTF-8?q?=EF=BC=8C=E7=94=A8=E4=BA=8E=E5=BF=BD=E7=95=A5=E2=80=9C=E6=97=A0?= =?UTF-8?q?=E6=95=88=E7=9A=84=E5=88=B7=E6=96=B0=E4=BB=A4=E7=89=8C=E2=80=9D?= =?UTF-8?q?=E7=AD=89=E9=9D=9E=E5=85=B3=E9=94=AE=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/core/handler/GlobalExceptionHandler.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java index 46aa1eb4b..845a84c6a 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java @@ -7,6 +7,7 @@ import cn.hutool.extra.servlet.JakartaServletUtil; import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService; import cn.iocoder.yudao.framework.common.exception.ServiceException; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.collection.SetUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; @@ -32,6 +33,7 @@ import org.springframework.web.servlet.NoHandlerFoundException; import java.time.LocalDateTime; import java.util.Map; +import java.util.Set; import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.*; @@ -45,6 +47,11 @@ import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeC @Slf4j public class GlobalExceptionHandler { + /** + * 忽略的 ServiceException 错误提示,避免打印过多 logger + */ + public static final Set IGNORE_ERROR_MESSAGES = SetUtils.asSet("无效的刷新令牌"); + @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") private final String applicationName; @@ -199,7 +206,10 @@ public class GlobalExceptionHandler { */ @ExceptionHandler(value = ServiceException.class) public CommonResult serviceExceptionHandler(ServiceException ex) { - log.info("[serviceExceptionHandler]", ex); + if (!IGNORE_ERROR_MESSAGES.contains(ex.getMessage())) { + // 不包含的时候,才进行打印,避免 ex 堆栈过多 + log.info("[serviceExceptionHandler]", ex); + } return CommonResult.error(ex.getCode(), ex.getMessage()); }