美团配送添加限流错误处理
This commit is contained in:
@@ -82,6 +82,7 @@ const (
|
||||
const (
|
||||
ResponseCodeSuccess = 0
|
||||
ResponseCodeInvalidParam = 4 // 参数格式错误
|
||||
ResponseCodeFlowControl = 11 // 接口流控
|
||||
ResponseCodeShopNotExist = 112 // 门店不存在
|
||||
)
|
||||
|
||||
@@ -165,6 +166,12 @@ type API struct {
|
||||
config *platformapi.APIConfig
|
||||
}
|
||||
|
||||
var (
|
||||
exceedLimitCodes = map[int]int{
|
||||
ResponseCodeFlowControl: 1,
|
||||
}
|
||||
)
|
||||
|
||||
func New(appKey, secret string, config ...*platformapi.APIConfig) *API {
|
||||
curConfig := platformapi.DefAPIConfig
|
||||
if len(config) > 0 {
|
||||
@@ -246,6 +253,9 @@ func (a *API) AccessAPI2(baseURL, action string, params map[string]interface{})
|
||||
}
|
||||
retVal.Message, _ = jsonResult1[msgKey].(string)
|
||||
newErr := utils.NewErrorIntCode(retVal.Message, code)
|
||||
if _, ok := exceedLimitCodes[code]; ok {
|
||||
return platformapi.ErrLevelExceedLimit, newErr
|
||||
}
|
||||
return platformapi.ErrLevelCodeIsNotOK, newErr
|
||||
})
|
||||
return retVal, err
|
||||
|
||||
Reference in New Issue
Block a user