美团配送添加限流错误处理
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
|
||||
|
||||
@@ -57,89 +57,6 @@ func TestAccessAPI(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateOrderByShop(t *testing.T) {
|
||||
basicParams := &CreateOrderByShopParam{
|
||||
DeliveryID: 123456789,
|
||||
OrderID: "order_123456789",
|
||||
// 设置测试门店 id,测试门店的坐标地址为 97235456,31065079(高德坐标),配送范围3km
|
||||
ShopID: "test_0001",
|
||||
DeliveryServiceCode: DeliveryServiceCodeIntime,
|
||||
ReceiverName: "xjh",
|
||||
ReceiverAddress: "九里堤",
|
||||
ReceiverPhone: "18112345678",
|
||||
ReceiverLng: 97235456,
|
||||
ReceiverLat: 31065079,
|
||||
CoordinateType: CoordinateTypeMars,
|
||||
GoodsValue: 12.34,
|
||||
GoodsWeight: 3.4,
|
||||
OrderType: OrderTypeASAP,
|
||||
}
|
||||
|
||||
order, err := api.CreateOrderByShop(basicParams, nil)
|
||||
handleError(t, err)
|
||||
if order != nil {
|
||||
sugarLogger.Debugf("order:%v", order)
|
||||
}
|
||||
}
|
||||
|
||||
func TestShopQuery(t *testing.T) {
|
||||
shopInfo, err := api.ShopQuery("not exist")
|
||||
if err == nil {
|
||||
t.Fatal("应该报错找不到门店")
|
||||
}
|
||||
shopInfo, err = api.ShopQuery("11726346")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(shopInfo, false))
|
||||
}
|
||||
|
||||
func TestShopCreate(t *testing.T) {
|
||||
shopInfo := &ShopInfo{
|
||||
ShopID: "11726346",
|
||||
ShopName: "测试门店",
|
||||
Category: ShopCategoryFruit,
|
||||
SecondCategory: ShopCategoryFruitFruit,
|
||||
ContactName: "徐",
|
||||
ContactPhone: "18180948107",
|
||||
ShopAddress: "北京市通州区五所南路与玉桥西路南延交叉口北100米梨园农副产品交易中心 水果区",
|
||||
ShopLng: 116672496,
|
||||
ShopLat: 39879491,
|
||||
CoordinateType: CoordinateTypeMars,
|
||||
DeliveryServiceCodes: utils.Int2Str(DeliveryServiceCodeRapid),
|
||||
BusinessHours: "[{\"beginTime\":\"09:00\",\"endTime\":\"18:00\"}]",
|
||||
}
|
||||
_, err := api.ShopCreate(shopInfo)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimulateArrange(t *testing.T) {
|
||||
err := api.SimulateArrange(123456789, "1529387562097059")
|
||||
handleError(t, err)
|
||||
}
|
||||
|
||||
func TestSimulatePickup(t *testing.T) {
|
||||
err := api.SimulatePickup(123456789, "1529387562097059")
|
||||
handleError(t, err)
|
||||
}
|
||||
|
||||
func TestSimulateRearrange(t *testing.T) {
|
||||
err := api.SimulateRearrange(123456789, "1529387562097059")
|
||||
handleError(t, err)
|
||||
}
|
||||
|
||||
func TestSimulateDeliver(t *testing.T) {
|
||||
err := api.SimulateDeliver(123456789, "1529387562097059")
|
||||
handleError(t, err)
|
||||
}
|
||||
|
||||
func TestSimulateReportException(t *testing.T) {
|
||||
err := api.SimulateReportException(123456789, "1529387562097059")
|
||||
handleError(t, err)
|
||||
}
|
||||
|
||||
func TestCancelOrder(t *testing.T) {
|
||||
result, err := api.CancelOrder(123456789, "1529387562097059", CancelReasonMerchantOther, "just a test")
|
||||
handleError(t, err)
|
||||
|
||||
@@ -2,6 +2,8 @@ package mtpsapi
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
func TestSimulateShopStatus(t *testing.T) {
|
||||
@@ -10,3 +12,86 @@ func TestSimulateShopStatus(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateOrderByShop(t *testing.T) {
|
||||
basicParams := &CreateOrderByShopParam{
|
||||
DeliveryID: 123456789,
|
||||
OrderID: "order_123456789",
|
||||
// 设置测试门店 id,测试门店的坐标地址为 97235456,31065079(高德坐标),配送范围3km
|
||||
ShopID: "test_0001",
|
||||
DeliveryServiceCode: DeliveryServiceCodeIntime,
|
||||
ReceiverName: "xjh",
|
||||
ReceiverAddress: "九里堤",
|
||||
ReceiverPhone: "18112345678",
|
||||
ReceiverLng: 97235456,
|
||||
ReceiverLat: 31065079,
|
||||
CoordinateType: CoordinateTypeMars,
|
||||
GoodsValue: 12.34,
|
||||
GoodsWeight: 3.4,
|
||||
OrderType: OrderTypeASAP,
|
||||
}
|
||||
|
||||
order, err := api.CreateOrderByShop(basicParams, nil)
|
||||
handleError(t, err)
|
||||
if order != nil {
|
||||
sugarLogger.Debugf("order:%v", order)
|
||||
}
|
||||
}
|
||||
|
||||
func TestShopQuery(t *testing.T) {
|
||||
shopInfo, err := api.ShopQuery("not exist")
|
||||
if err == nil {
|
||||
t.Fatal("应该报错找不到门店")
|
||||
}
|
||||
shopInfo, err = api.ShopQuery("11733028")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(shopInfo, false))
|
||||
}
|
||||
|
||||
func TestShopCreate(t *testing.T) {
|
||||
shopInfo := &ShopInfo{
|
||||
ShopID: "11726346",
|
||||
ShopName: "测试门店",
|
||||
Category: ShopCategoryFruit,
|
||||
SecondCategory: ShopCategoryFruitFruit,
|
||||
ContactName: "徐",
|
||||
ContactPhone: "18180948107",
|
||||
ShopAddress: "北京市通州区五所南路与玉桥西路南延交叉口北100米梨园农副产品交易中心 水果区",
|
||||
ShopLng: 116672496,
|
||||
ShopLat: 39879491,
|
||||
CoordinateType: CoordinateTypeMars,
|
||||
DeliveryServiceCodes: utils.Int2Str(DeliveryServiceCodeRapid),
|
||||
BusinessHours: "[{\"beginTime\":\"09:00\",\"endTime\":\"18:00\"}]",
|
||||
}
|
||||
_, err := api.ShopCreate(shopInfo)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimulateArrange(t *testing.T) {
|
||||
err := api.SimulateArrange(123456789, "1529387562097059")
|
||||
handleError(t, err)
|
||||
}
|
||||
|
||||
func TestSimulatePickup(t *testing.T) {
|
||||
err := api.SimulatePickup(123456789, "1529387562097059")
|
||||
handleError(t, err)
|
||||
}
|
||||
|
||||
func TestSimulateRearrange(t *testing.T) {
|
||||
err := api.SimulateRearrange(123456789, "1529387562097059")
|
||||
handleError(t, err)
|
||||
}
|
||||
|
||||
func TestSimulateDeliver(t *testing.T) {
|
||||
err := api.SimulateDeliver(123456789, "1529387562097059")
|
||||
handleError(t, err)
|
||||
}
|
||||
|
||||
func TestSimulateReportException(t *testing.T) {
|
||||
err := api.SimulateReportException(123456789, "1529387562097059")
|
||||
handleError(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user