fix:ApiErrorLogServiceImpl 在微服务场景下,记录日志存在的循环调用的问题

This commit is contained in:
YunaiV
2025-07-26 21:21:02 +08:00
parent 77193102a2
commit 99442ec05c

View File

@@ -40,11 +40,16 @@ public class ApiErrorLogServiceImpl implements ApiErrorLogService {
ApiErrorLogDO apiErrorLog = BeanUtils.toBean(createDTO, ApiErrorLogDO.class)
.setProcessStatus(ApiErrorLogProcessStatusEnum.INIT.getStatus());
apiErrorLog.setRequestParams(StrUtils.maxLength(apiErrorLog.getRequestParams(), REQUEST_PARAMS_MAX_LENGTH));
if (TenantContextHolder.getTenantId() != null) {
apiErrorLogMapper.insert(apiErrorLog);
} else {
// 极端情况下,上下文中没有租户时,此时忽略租户上下文,避免插入失败!
TenantUtils.executeIgnore(() -> apiErrorLogMapper.insert(apiErrorLog));
try {
if (TenantContextHolder.getTenantId() != null) {
apiErrorLogMapper.insert(apiErrorLog);
} else {
// 极端情况下,上下文中没有租户时,此时忽略租户上下文,避免插入失败!
TenantUtils.executeIgnore(() -> apiErrorLogMapper.insert(apiErrorLog));
}
} catch (Exception ex) {
// 兜底处理,目前只有 yudao-cloud 会发生https://gitee.com/yudaocode/yudao-cloud-mini/issues/IC1O0A
log.error("[createApiErrorLog][记录时({}) 发生异常]", createDTO, ex);
}
}