This commit is contained in:
Mrx
2026-03-23 12:36:23 +08:00
parent 6a801acee1
commit 8eec9685db

View File

@@ -222,13 +222,12 @@ func (j *JiguangService) CallAPI(ctx context.Context, apiCode string, apiPath st
}
// 检查业务状态码
if jiguangResp.Code != 0 && jiguangResp.Code != 200 {
if jiguangResp.Code != 0 && jiguangResp.Code != 200 && jiguangResp.Code != 400 {
// 创建极光错误
jiguangErr := NewJiguangErrorFromCode(jiguangResp.Code)
if jiguangErr.Message == fmt.Sprintf("未知错误码: %d", jiguangResp.Code) && jiguangResp.Msg != "" {
jiguangErr.Message = jiguangResp.Msg
}
// 根据错误类型返回不同的错误
if jiguangErr.IsNoRecord() {
// 从context中获取apiCode判断是否需要抛出异常
@@ -236,33 +235,27 @@ func (j *JiguangService) CallAPI(ctx context.Context, apiCode string, apiPath st
if ctxProcessorCode, ok := ctx.Value("api_code").(string); ok {
processorCode = ctxProcessorCode
}
// 定义不需要抛出异常的处理器列表(默认情况下查无记录时抛出异常)
processorsNotToThrowError := map[string]bool{
// 在这个列表中的处理器,查无记录时返回空数组,不抛出异常
// 示例:如果需要添加某个处理器,取消下面的注释
// "QCXG9P1C": true,
}
// 如果是不需要抛出异常的处理器,返回空数组;否则(默认)抛出异常
if processorsNotToThrowError[processorCode] {
// 查无记录时返回空数组API调用记录为成功
return []byte("[]"), nil
}
// 默认情况下,查无记录时抛出异常
// 记录错误日志
if j.logger != nil {
j.logger.LogErrorWithResponseID(requestID, transactionID, apiCode, jiguangErr, params, jiguangResp.OrderID)
}
return nil, errors.Join(ErrNotFound, jiguangErr)
}
// 记录错误日志(查无记录的情况不记录错误日志)
if j.logger != nil {
j.logger.LogErrorWithResponseID(requestID, transactionID, apiCode, jiguangErr, params, jiguangResp.OrderID)
}
if jiguangErr.IsQueryFailed() {
return nil, errors.Join(ErrDatasource, jiguangErr)
} else if jiguangErr.IsSystemError() {
@@ -272,11 +265,6 @@ func (j *JiguangService) CallAPI(ctx context.Context, apiCode string, apiPath st
}
}
// 成功响应返回data字段
if jiguangResp.Data == nil {
return []byte("{}"), nil
}
// 将data转换为JSON字节
dataBytes, err := json.Marshal(jiguangResp.Data)
if err != nil {