feat: 添加 muzi 服务并接入 ivyz3p9m
This commit is contained in:
@@ -18,23 +18,23 @@ import (
|
||||
|
||||
// 行为数据API状态码常量
|
||||
const (
|
||||
CodeSuccess = 200 // 操作成功
|
||||
CodeSystemError = 500 // 系统内部错误
|
||||
CodeMerchantError = 3001 // 商家相关报错(商家不存在、商家被禁用、商家余额不足)
|
||||
CodeAccountExpired = 3002 // 账户已过期
|
||||
CodeIPWhitelistMissing = 3003 // 未添加ip白名单
|
||||
CodeUnauthorized = 3004 // 未授权调用该接口
|
||||
CodeProductIDError = 4001 // 产品id错误
|
||||
CodeInterfaceDisabled = 4002 // 接口被停用
|
||||
CodeQueryException = 5001 // 接口查询异常,请联系技术人员
|
||||
CodeNotFound = 6000 // 未查询到结果
|
||||
CodeSuccess = 200 // 操作成功
|
||||
CodeSystemError = 500 // 系统内部错误
|
||||
CodeMerchantError = 3001 // 商家相关报错(商家不存在、商家被禁用、商家余额不足)
|
||||
CodeAccountExpired = 3002 // 账户已过期
|
||||
CodeIPWhitelistMissing = 3003 // 未添加ip白名单
|
||||
CodeUnauthorized = 3004 // 未授权调用该接口
|
||||
CodeProductIDError = 4001 // 产品id错误
|
||||
CodeInterfaceDisabled = 4002 // 接口被停用
|
||||
CodeQueryException = 5001 // 接口查询异常,请联系技术人员
|
||||
CodeNotFound = 6000 // 未查询到结果
|
||||
)
|
||||
|
||||
var (
|
||||
ErrDatasource = errors.New("数据源异常")
|
||||
ErrSystem = errors.New("系统异常")
|
||||
ErrNotFound = errors.New("未查询到结果")
|
||||
|
||||
|
||||
// 请求ID计数器,确保唯一性
|
||||
requestIDCounter int64
|
||||
)
|
||||
@@ -54,16 +54,16 @@ type XingweiErrorCode struct {
|
||||
|
||||
// 行为数据错误码映射
|
||||
var XingweiErrorCodes = map[int]XingweiErrorCode{
|
||||
CodeSuccess: {Code: CodeSuccess, Message: "操作成功"},
|
||||
CodeSystemError: {Code: CodeSystemError, Message: "系统内部错误"},
|
||||
CodeMerchantError: {Code: CodeMerchantError, Message: "商家相关报错(商家不存在、商家被禁用、商家余额不足)"},
|
||||
CodeAccountExpired: {Code: CodeAccountExpired, Message: "账户已过期"},
|
||||
CodeIPWhitelistMissing: {Code: CodeIPWhitelistMissing, Message: "未添加ip白名单"},
|
||||
CodeUnauthorized: {Code: CodeUnauthorized, Message: "未授权调用该接口"},
|
||||
CodeProductIDError: {Code: CodeProductIDError, Message: "产品id错误"},
|
||||
CodeInterfaceDisabled: {Code: CodeInterfaceDisabled, Message: "接口被停用"},
|
||||
CodeQueryException: {Code: CodeQueryException, Message: "接口查询异常,请联系技术人员"},
|
||||
CodeNotFound: {Code: CodeNotFound, Message: "未查询到结果"},
|
||||
CodeSuccess: {Code: CodeSuccess, Message: "操作成功"},
|
||||
CodeSystemError: {Code: CodeSystemError, Message: "系统内部错误"},
|
||||
CodeMerchantError: {Code: CodeMerchantError, Message: "商家相关报错(商家不存在、商家被禁用、商家余额不足)"},
|
||||
CodeAccountExpired: {Code: CodeAccountExpired, Message: "账户已过期"},
|
||||
CodeIPWhitelistMissing: {Code: CodeIPWhitelistMissing, Message: "未添加ip白名单"},
|
||||
CodeUnauthorized: {Code: CodeUnauthorized, Message: "未授权调用该接口"},
|
||||
CodeProductIDError: {Code: CodeProductIDError, Message: "产品id错误"},
|
||||
CodeInterfaceDisabled: {Code: CodeInterfaceDisabled, Message: "接口被停用"},
|
||||
CodeQueryException: {Code: CodeQueryException, Message: "接口查询异常,请联系技术人员"},
|
||||
CodeNotFound: {Code: CodeNotFound, Message: "未查询到结果"},
|
||||
}
|
||||
|
||||
// GetXingweiErrorMessage 根据错误码获取错误消息
|
||||
@@ -172,14 +172,13 @@ func (x *XingweiService) CallAPI(ctx context.Context, projectID string, params m
|
||||
isTimeout = true
|
||||
} else if netErr, ok := clientDoErr.(interface{ Timeout() bool }); ok && netErr.Timeout() {
|
||||
isTimeout = true
|
||||
} else if errStr := clientDoErr.Error();
|
||||
errStr == "context deadline exceeded" ||
|
||||
errStr == "timeout" ||
|
||||
errStr == "Client.Timeout exceeded" ||
|
||||
errStr == "net/http: request canceled" {
|
||||
} else if errStr := clientDoErr.Error(); errStr == "context deadline exceeded" ||
|
||||
errStr == "timeout" ||
|
||||
errStr == "Client.Timeout exceeded" ||
|
||||
errStr == "net/http: request canceled" {
|
||||
isTimeout = true
|
||||
}
|
||||
|
||||
|
||||
if isTimeout {
|
||||
err = errors.Join(ErrDatasource, fmt.Errorf("API请求超时: %v", clientDoErr))
|
||||
} else {
|
||||
@@ -244,7 +243,7 @@ func (x *XingweiService) CallAPI(ctx context.Context, projectID string, params m
|
||||
if xingweiResp.Data == nil {
|
||||
return []byte("{}"), nil
|
||||
}
|
||||
|
||||
|
||||
// 将data转换为JSON字节
|
||||
dataBytes, err := json.Marshal(xingweiResp.Data)
|
||||
if err != nil {
|
||||
@@ -254,39 +253,39 @@ func (x *XingweiService) CallAPI(ctx context.Context, projectID string, params m
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
return dataBytes, nil
|
||||
|
||||
|
||||
case CodeNotFound:
|
||||
// 未查询到结果,返回查空错误
|
||||
if x.logger != nil {
|
||||
x.logger.LogError(requestID, transactionID, "xingwei_api",
|
||||
x.logger.LogError(requestID, transactionID, "xingwei_api",
|
||||
errors.Join(ErrNotFound, fmt.Errorf("未查询到结果")), params)
|
||||
}
|
||||
return nil, errors.Join(ErrNotFound, fmt.Errorf("未查询到结果"))
|
||||
|
||||
|
||||
case CodeSystemError:
|
||||
// 系统内部错误
|
||||
errorMsg := GetXingweiErrorMessage(xingweiResp.Code)
|
||||
systemErr := fmt.Errorf("行为数据系统错误[%d]: %s", xingweiResp.Code, errorMsg)
|
||||
|
||||
|
||||
if x.logger != nil {
|
||||
x.logger.LogError(requestID, transactionID, "xingwei_api",
|
||||
x.logger.LogError(requestID, transactionID, "xingwei_api",
|
||||
errors.Join(ErrSystem, systemErr), params)
|
||||
}
|
||||
|
||||
|
||||
return nil, errors.Join(ErrSystem, systemErr)
|
||||
|
||||
|
||||
default:
|
||||
// 其他业务错误
|
||||
errorMsg := GetXingweiErrorMessage(xingweiResp.Code)
|
||||
businessErr := fmt.Errorf("行为数据业务错误[%d]: %s", xingweiResp.Code, errorMsg)
|
||||
|
||||
|
||||
if x.logger != nil {
|
||||
x.logger.LogError(requestID, transactionID, "xingwei_api",
|
||||
x.logger.LogError(requestID, transactionID, "xingwei_api",
|
||||
errors.Join(ErrDatasource, businessErr), params)
|
||||
}
|
||||
|
||||
|
||||
return nil, errors.Join(ErrDatasource, businessErr)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user