This commit is contained in:
Mrx
2026-01-19 14:28:21 +08:00
parent 2d5c2120fb
commit 85bd011fd3
2 changed files with 25 additions and 0 deletions

View File

@@ -278,6 +278,9 @@ func (a *ApiRequestService) PreprocessRequestApi(ctx context.Context, apiCode st
// 设置Options和CallContext到依赖容器 // 设置Options和CallContext到依赖容器
deps := a.processorDeps.WithOptions(options).WithCallContext(callContext) deps := a.processorDeps.WithOptions(options).WithCallContext(callContext)
// 将apiCode放入context供外部服务使用
ctx = context.WithValue(ctx, "api_code", apiCode)
// 1. 优先查找已注册的自定义处理器 // 1. 优先查找已注册的自定义处理器
if processor, exists := RequestProcessors[apiCode]; exists { if processor, exists := RequestProcessors[apiCode]; exists {
return processor(ctx, params, deps) return processor(ctx, params, deps)

View File

@@ -231,6 +231,28 @@ func (j *JiguangService) CallAPI(ctx context.Context, apiCode string, apiPath st
// 根据错误类型返回不同的错误 // 根据错误类型返回不同的错误
if jiguangErr.IsNoRecord() { 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调用记录为成功 // 查无记录时返回空数组API调用记录为成功
return []byte("[]"), nil return []byte("[]"), nil
} }