f
This commit is contained in:
@@ -4,6 +4,17 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GetQueryEmptyErrByCode 将数据宝错误码归类为“查询为空/不扣费”错误。
|
||||||
|
// 说明:上游通常依赖 errors.Is(err, ErrQueryEmpty) 来决定是否扣费。
|
||||||
|
func GetQueryEmptyErrByCode(code string) error {
|
||||||
|
switch code {
|
||||||
|
case "10001", "10006":
|
||||||
|
return ErrQueryEmpty
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ShujubaoError 数据宝服务错误
|
// ShujubaoError 数据宝服务错误
|
||||||
type ShujubaoError struct {
|
type ShujubaoError struct {
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
|
|||||||
@@ -292,14 +292,26 @@ func (s *ShujubaoService) CallAPI(ctx context.Context, apiPath string, params ma
|
|||||||
}
|
}
|
||||||
|
|
||||||
code := shujubaoResp.Code
|
code := shujubaoResp.Code
|
||||||
if code == "10001" || code == "10006" {
|
|
||||||
// 查空/查无:返回空数组,不视为错误
|
// 成功码只有这三类:其它 code 都走统一错误映射返回
|
||||||
return []interface{}{}, nil
|
if code != "10000" && code != "200" && code != "0" {
|
||||||
}
|
// 将上游失败返回码单独记录到日志参数中,便于排查与统计
|
||||||
if code != "10000" {
|
logParams := paramsForLog(params)
|
||||||
|
if logParams == nil {
|
||||||
|
logParams = map[string]interface{}{}
|
||||||
|
}
|
||||||
|
logParams["shujubao_return_code"] = code
|
||||||
|
|
||||||
shujubaoErr := NewShujubaoErrorFromCode(code, shujubaoResp.Message)
|
shujubaoErr := NewShujubaoErrorFromCode(code, shujubaoResp.Message)
|
||||||
|
if queryEmptyErr := GetQueryEmptyErrByCode(code); queryEmptyErr != nil {
|
||||||
|
err = errors.Join(queryEmptyErr, shujubaoErr)
|
||||||
|
if s.logger != nil {
|
||||||
|
s.logger.LogError(requestID, transactionID, apiPath, err, logParams)
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
if s.logger != nil {
|
if s.logger != nil {
|
||||||
s.logger.LogError(requestID, transactionID, apiPath, shujubaoErr, paramsForLog(params))
|
s.logger.LogError(requestID, transactionID, apiPath, shujubaoErr, logParams)
|
||||||
}
|
}
|
||||||
return nil, errors.Join(ErrDatasource, shujubaoErr)
|
return nil, errors.Join(ErrDatasource, shujubaoErr)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user