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

pull/119/MERGE
YunaiV 2024-05-03 09:53:00 +08:00
parent 1e23316fb1
commit 6fc6fb1bc8
1 changed files with 11 additions and 1 deletions

View File

@ -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<String> 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());
}