This commit is contained in:
Mrx
2026-01-23 17:53:11 +08:00
parent 6104bfb84f
commit b05c459b81
28 changed files with 1416 additions and 59 deletions

View File

@@ -22,7 +22,6 @@ import (
var (
ErrDatasource = errors.New("数据源异常")
ErrSystem = errors.New("系统异常")
ErrNotFound = errors.New("数据为空")
)
// contextKey 用于在 context 中存储不跳过 201 错误检查的标志
@@ -30,12 +29,6 @@ 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 {
Code string `json:"code"`
Message string `json:"message"`
@@ -200,24 +193,8 @@ func (z *ZhichaService) CallAPI(ctx context.Context, proID string, params map[st
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" {
// 创建智查金控错误用于日志记录
zhichaErr := NewZhichaErrorFromCode(zhichaResp.Code)
if zhichaErr.Code == "未知错误" {