From 85bd011fd3410a3fc2cccd1e0eb54e4a9d3e197b Mon Sep 17 00:00:00 2001 From: Mrx <18278715334@163.com> Date: Mon, 19 Jan 2026 14:28:21 +0800 Subject: [PATCH] f --- .../api/services/api_request_service.go | 3 +++ .../external/jiguang/jiguang_service.go | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/internal/domains/api/services/api_request_service.go b/internal/domains/api/services/api_request_service.go index 91caf06..8c04c66 100644 --- a/internal/domains/api/services/api_request_service.go +++ b/internal/domains/api/services/api_request_service.go @@ -278,6 +278,9 @@ func (a *ApiRequestService) PreprocessRequestApi(ctx context.Context, apiCode st // 设置Options和CallContext到依赖容器 deps := a.processorDeps.WithOptions(options).WithCallContext(callContext) + // 将apiCode放入context,供外部服务使用 + ctx = context.WithValue(ctx, "api_code", apiCode) + // 1. 优先查找已注册的自定义处理器 if processor, exists := RequestProcessors[apiCode]; exists { return processor(ctx, params, deps) diff --git a/internal/infrastructure/external/jiguang/jiguang_service.go b/internal/infrastructure/external/jiguang/jiguang_service.go index 447dffe..68a7aac 100644 --- a/internal/infrastructure/external/jiguang/jiguang_service.go +++ b/internal/infrastructure/external/jiguang/jiguang_service.go @@ -231,6 +231,28 @@ func (j *JiguangService) CallAPI(ctx context.Context, apiCode string, apiPath st // 根据错误类型返回不同的错误 if jiguangErr.IsNoRecord() { + // 从context中获取apiCode,判断是否需要抛出异常 + var processorCode string + if ctxProcessorCode, ok := ctx.Value("api_code").(string); ok { + processorCode = ctxProcessorCode + } + + // 定义需要在查无记录时抛出异常的处理器列表 + processorsToThrowError := map[string]bool{ + "QCXG9P1C": true, // QCXG9P1C 处理器在查无记录时需要抛出异常 + "QCXG4D2E": true, // QCXG4D2E 处理器在查无记录时需要抛出异常 + "QCXG5F3A": true, // QCXG5F3A 处理器在查无记录时需要抛出异常 + } + + // 如果是特定处理器,抛出异常;否则返回空数组 + if processorsToThrowError[processorCode] { + // 记录错误日志 + if j.logger != nil { + j.logger.LogErrorWithResponseID(requestID, transactionID, apiCode, jiguangErr, params, jiguangResp.OrderID) + } + return nil, errors.Join(ErrNotFound, jiguangErr) + } + // 查无记录时,返回空数组,API调用记录为成功 return []byte("[]"), nil }