This commit is contained in:
2025-10-21 15:23:03 +08:00
parent 3d3ca98eb7
commit 99d9405db0

View File

@@ -424,8 +424,21 @@ func (s *ApiApplicationServiceImpl) asyncRecordFailure(ctx context.Context, apiC
apiCall.MarkFailed(errorType, errorMsg)
// 失败请求不创建任务,只记录日志
s.logger.Info("API调用失败记录失败状态",
// 检查TransactionID是否已存在避免重复创建
existingCall, err := s.apiCallRepository.FindByTransactionId(ctx, apiCall.TransactionId)
if err == nil && existingCall != nil {
s.logger.Warn("API调用记录已存在跳过创建",
zap.String("transaction_id", apiCall.TransactionId))
return // 静默返回,不报错
}
// 保存失败的API调用记录到数据库
if err := s.apiCallRepository.Create(ctx, apiCall); err != nil {
s.logger.Error("保存失败API调用记录失败", zap.Error(err))
return
}
s.logger.Info("API调用失败已记录到数据库",
zap.String("transaction_id", apiCall.TransactionId),
zap.String("error_type", errorType),
zap.String("error_msg", errorMsg))