-f单独处理,null不计费
This commit is contained in:
@@ -46,10 +46,15 @@ func ProcessJRZQO6L7Request(ctx context.Context, params []byte, deps *processors
|
|||||||
"city": null,
|
"city": null,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 使用 WithSkipCode201Check 不跳过 201 错误检查,当 Code == "201" 时返回错误
|
||||||
|
ctx = zhicha.WithSkipCode201Check(ctx)
|
||||||
respData, err := deps.ZhichaService.CallAPI(ctx, "ZCI081", reqData)
|
respData, err := deps.ZhichaService.CallAPI(ctx, "ZCI081", reqData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, zhicha.ErrDatasource) {
|
if errors.Is(err, zhicha.ErrDatasource) {
|
||||||
return nil, errors.Join(processors.ErrDatasource, err)
|
return nil, errors.Join(processors.ErrDatasource, err)
|
||||||
|
}
|
||||||
|
if errors.Is(err, zhicha.ErrNotFound) {
|
||||||
|
return nil, errors.Join(processors.ErrNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.Join(processors.ErrSystem, err)
|
return nil, errors.Join(processors.ErrSystem, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,10 +47,15 @@ func ProcessJRZQO7L1Request(ctx context.Context, params []byte, deps *processors
|
|||||||
"city": null,
|
"city": null,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 使用 WithSkipCode201Check 不跳过 201 错误检查,当 Code == "201" 时返回错误
|
||||||
|
ctx = zhicha.WithSkipCode201Check(ctx)
|
||||||
respData, err := deps.ZhichaService.CallAPI(ctx, "ZCI080", reqData)
|
respData, err := deps.ZhichaService.CallAPI(ctx, "ZCI080", reqData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, zhicha.ErrDatasource) {
|
if errors.Is(err, zhicha.ErrDatasource) {
|
||||||
return nil, errors.Join(processors.ErrDatasource, err)
|
return nil, errors.Join(processors.ErrDatasource, err)
|
||||||
|
}
|
||||||
|
if errors.Is(err, zhicha.ErrNotFound) {
|
||||||
|
return nil, errors.Join(processors.ErrNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.Join(processors.ErrSystem, err)
|
return nil, errors.Join(processors.ErrSystem, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,16 +42,19 @@ func ProcessJRZQS7G0Request(ctx context.Context, params []byte, deps *processors
|
|||||||
"phone": encryptedMobileNo,
|
"phone": encryptedMobileNo,
|
||||||
"authorized": paramsDto.Authorized,
|
"authorized": paramsDto.Authorized,
|
||||||
}
|
}
|
||||||
|
// 使用 WithSkipCode201Check 不跳过 201 错误检查,当 Code == "201" 时返回错误
|
||||||
|
ctx = zhicha.WithSkipCode201Check(ctx)
|
||||||
respData, err := deps.ZhichaService.CallAPI(ctx, "ZCI082", reqData)
|
respData, err := deps.ZhichaService.CallAPI(ctx, "ZCI082", reqData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, zhicha.ErrDatasource) {
|
if errors.Is(err, zhicha.ErrDatasource) {
|
||||||
return nil, errors.Join(processors.ErrDatasource, err)
|
return nil, errors.Join(processors.ErrDatasource, err)
|
||||||
|
}
|
||||||
|
if errors.Is(err, zhicha.ErrNotFound) {
|
||||||
|
return nil, errors.Join(processors.ErrNotFound, err)
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.Join(processors.ErrSystem, err)
|
return nil, errors.Join(processors.ErrSystem, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将响应数据转换为JSON字节
|
// 将响应数据转换为JSON字节
|
||||||
respBytes, err := json.Marshal(respData)
|
respBytes, err := json.Marshal(respData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -22,8 +22,20 @@ import (
|
|||||||
var (
|
var (
|
||||||
ErrDatasource = errors.New("数据源异常")
|
ErrDatasource = errors.New("数据源异常")
|
||||||
ErrSystem = errors.New("系统异常")
|
ErrSystem = errors.New("系统异常")
|
||||||
|
ErrNotFound = errors.New("数据为空")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// contextKey 用于在 context 中存储不跳过 201 错误检查的标志
|
||||||
|
type contextKey string
|
||||||
|
|
||||||
|
const dontSkipCode201CheckKey contextKey = "dont_skip_code_201_check"
|
||||||
|
|
||||||
|
// WithSkipCode201Check 返回一个设置了不跳过 201 错误检查标志的 context
|
||||||
|
// 默认情况下会跳过 201 检查(继续执行),使用此函数后会在 Code == "201" 时返回错误
|
||||||
|
func WithSkipCode201Check(ctx context.Context) context.Context {
|
||||||
|
return context.WithValue(ctx, dontSkipCode201CheckKey, true)
|
||||||
|
}
|
||||||
|
|
||||||
type ZhichaResp struct {
|
type ZhichaResp struct {
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
@@ -188,6 +200,22 @@ func (z *ZhichaService) CallAPI(ctx context.Context, proID string, params map[st
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查是否需要不跳过 201 错误检查(默认跳过,继续执行)
|
||||||
|
// 如果设置了 dontSkipCode201CheckKey,则返回错误
|
||||||
|
dontSkipCode201Check := false
|
||||||
|
if dontSkip, ok := ctx.Value(dontSkipCode201CheckKey).(bool); ok {
|
||||||
|
dontSkipCode201Check = dontSkip
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果设置了不跳过检查,当 Code == "201" 时返回错误
|
||||||
|
if zhichaResp.Code == "201" && dontSkipCode201Check {
|
||||||
|
if z.logger != nil {
|
||||||
|
z.logger.LogError(requestID, transactionID, proID, ErrNotFound, params)
|
||||||
|
}
|
||||||
|
return nil, ErrNotFound
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// 检查业务状态码
|
// 检查业务状态码
|
||||||
if zhichaResp.Code != "200" && zhichaResp.Code != "201" {
|
if zhichaResp.Code != "200" && zhichaResp.Code != "201" {
|
||||||
// 创建智查金控错误用于日志记录
|
// 创建智查金控错误用于日志记录
|
||||||
|
|||||||
Reference in New Issue
Block a user