fix
This commit is contained in:
@@ -424,8 +424,21 @@ func (s *ApiApplicationServiceImpl) asyncRecordFailure(ctx context.Context, apiC
|
|||||||
|
|
||||||
apiCall.MarkFailed(errorType, errorMsg)
|
apiCall.MarkFailed(errorType, errorMsg)
|
||||||
|
|
||||||
// 失败请求不创建任务,只记录日志
|
// 检查TransactionID是否已存在,避免重复创建
|
||||||
s.logger.Info("API调用失败,记录失败状态",
|
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("transaction_id", apiCall.TransactionId),
|
||||||
zap.String("error_type", errorType),
|
zap.String("error_type", errorType),
|
||||||
zap.String("error_msg", errorMsg))
|
zap.String("error_msg", errorMsg))
|
||||||
|
|||||||
Reference in New Issue
Block a user