- return result even error in dada api
This commit is contained in:
@@ -18,11 +18,13 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
ResponseCodeException = -1
|
||||
ResponseCodeSuccess = 0
|
||||
ResponseCodeSignErr = 2003
|
||||
ResponseCodeRetryLater = 2012
|
||||
ResponseCodeNetworkErr = 2455
|
||||
ResponseCodeException = -1
|
||||
ResponseCodeSuccess = 0
|
||||
ResponseCodeSignErr = 2003
|
||||
ResponseCodeRetryLater = 2012
|
||||
ResponseCodeShopNotExist = 2402
|
||||
ResponseCodeShopAlreadyExist = 2403
|
||||
ResponseCodeNetworkErr = 2455
|
||||
)
|
||||
|
||||
type API struct {
|
||||
@@ -124,8 +126,8 @@ func (a *API) AccessAPI(action string, params interface{}) (retVal *ResponseResu
|
||||
Msg: jsonResult1["msg"].(string),
|
||||
Status: jsonResult1["status"].(string),
|
||||
}
|
||||
retVal.Result = jsonResult1["result"]
|
||||
if code == ResponseCodeSuccess {
|
||||
retVal.Result = jsonResult1["result"]
|
||||
return platformapi.ErrLevelSuccess, nil
|
||||
}
|
||||
newErr := utils.NewErrorIntCode(retVal.Msg, code)
|
||||
|
||||
@@ -50,8 +50,11 @@ func (a *API) ShopAdd(originShopID, stationName string, business int, cityName,
|
||||
if addParams != nil {
|
||||
params = utils.MergeMaps(params, addParams)
|
||||
}
|
||||
successList, _, err := a.BatchShopAdd([]map[string]interface{}{params})
|
||||
successList, failedList, err := a.BatchShopAdd([]map[string]interface{}{params})
|
||||
if err != nil {
|
||||
if len(failedList) == 1 {
|
||||
return "", utils.NewErrorIntCode(failedList[0]["msg"].(string), int(utils.MustInterface2Int64(failedList[0]["code"])))
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
return utils.Interface2String(successList[0]["originShopId"]), nil
|
||||
@@ -59,9 +62,6 @@ func (a *API) ShopAdd(originShopID, stationName string, business int, cityName,
|
||||
|
||||
func (a *API) BatchShopAdd(shopInfoList []map[string]interface{}) (successList, failedList []map[string]interface{}, err error) {
|
||||
result, err := a.AccessAPI("api/shop/add", shopInfoList)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
mapResult := result.Result.(map[string]interface{})
|
||||
if successList2 := mapResult["successList"]; successList2 != nil {
|
||||
successList = utils.Slice2MapSlice(successList2.([]interface{}))
|
||||
@@ -69,7 +69,7 @@ func (a *API) BatchShopAdd(shopInfoList []map[string]interface{}) (successList,
|
||||
if failedList2 := mapResult["failedList"]; failedList2 != nil {
|
||||
failedList = utils.Slice2MapSlice(failedList2.([]interface{}))
|
||||
}
|
||||
return successList, failedList, nil
|
||||
return successList, failedList, err
|
||||
}
|
||||
|
||||
func (a *API) ShopUpdate(originShopID string, shopInfo map[string]interface{}) (err error) {
|
||||
|
||||
@@ -132,6 +132,7 @@ func AccessPlatformAPIWithRetry(client *http.Client, handleRequest func() *http.
|
||||
} else {
|
||||
errLevel, err = handleResponse(bodyMap)
|
||||
}
|
||||
// baseapi.SugarLogger.Debugf("AccessPlatformAPIWithRetry url:%v, request:%v, response:%s", request.URL, getClonedData(savedBuf), utils.Format4Output(bodyMap, true))
|
||||
if err == nil {
|
||||
return nil
|
||||
} else if errLevel == ErrLevelExceedLimit {
|
||||
@@ -146,7 +147,7 @@ func AccessPlatformAPIWithRetry(client *http.Client, handleRequest func() *http.
|
||||
continue
|
||||
}
|
||||
}
|
||||
baseapi.SugarLogger.Infof("AccessPlatformAPIWithRetry failed, url:%v, request:%v, response:%v, error:%v", request.URL, getClonedData(savedBuf), response, err)
|
||||
baseapi.SugarLogger.Infof("AccessPlatformAPIWithRetry failed, url:%v, request:%v, response:%s, error:%v", request.URL, getClonedData(savedBuf), utils.Format4Output(bodyMap, true), err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user