美团配送添加限流错误处理

This commit is contained in:
gazebo
2019-10-11 16:09:57 +08:00
parent a5559d7042
commit 2e08ddebeb
3 changed files with 95 additions and 83 deletions

View File

@@ -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