- refactor RebuildError
- output store and sku info when mtwm api failed
This commit is contained in:
@@ -128,23 +128,11 @@ func (a *API) AccessAPI(cmd string, body map[string]interface{}) (retVal *Respon
|
||||
}
|
||||
return platformapi.ErrLevelCodeIsNotOK, newErr
|
||||
})
|
||||
if err != nil {
|
||||
if codeErr, ok := err.(*utils.ErrorWithCode); ok {
|
||||
appendErrList := []string{}
|
||||
for _, key := range []string{
|
||||
KeyBaiduShopID,
|
||||
KeyShopID,
|
||||
KeySkuID,
|
||||
KeyCustomSkuID,
|
||||
} {
|
||||
if body[key] != nil {
|
||||
appendErrList = append(appendErrList, fmt.Sprintf("[%s:%v]", key, body[key]))
|
||||
}
|
||||
}
|
||||
if len(appendErrList) > 0 {
|
||||
err = utils.NewErrorCode(strings.Join(appendErrList, ",")+", "+codeErr.ErrMsg(), codeErr.Code())
|
||||
}
|
||||
}
|
||||
}
|
||||
err = platformapi.RebuildError(err, body, []string{
|
||||
KeyBaiduShopID,
|
||||
KeyShopID,
|
||||
KeySkuID,
|
||||
KeyCustomSkuID,
|
||||
})
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
@@ -101,6 +101,11 @@ var (
|
||||
|
||||
var (
|
||||
nullResultParser = genNoPageResultParser("code", "msg", "", "0")
|
||||
watchKeys = []string{
|
||||
KeyOutStationNo,
|
||||
KeyStationNo,
|
||||
"StoreNo",
|
||||
}
|
||||
)
|
||||
|
||||
type PageResultParser func(map[string]interface{}, int) ([]interface{}, int, error)
|
||||
@@ -196,28 +201,7 @@ func (a *API) AccessAPI(apiStr string, jdParams map[string]interface{}) (retVal
|
||||
return platformapi.ErrLevelCodeIsNotOK, newErr
|
||||
}
|
||||
})
|
||||
return retVal, a.rebuildError(err, jdParams)
|
||||
}
|
||||
|
||||
func (a *API) rebuildError(inErr error, jdParams map[string]interface{}) (outErr error) {
|
||||
if inErr != nil {
|
||||
if codeErr, ok := inErr.(*utils.ErrorWithCode); ok {
|
||||
appendErrList := []string{}
|
||||
for _, key := range []string{
|
||||
KeyOutStationNo,
|
||||
KeyStationNo,
|
||||
"StoreNo",
|
||||
} {
|
||||
if jdParams[key] != nil {
|
||||
appendErrList = append(appendErrList, fmt.Sprintf("[%s:%v]", key, jdParams[key]))
|
||||
}
|
||||
}
|
||||
if len(appendErrList) > 0 {
|
||||
inErr = utils.NewErrorCode(strings.Join(appendErrList, ",")+", "+codeErr.ErrMsg(), codeErr.Code())
|
||||
}
|
||||
}
|
||||
}
|
||||
return inErr
|
||||
return retVal, platformapi.RebuildError(err, jdParams, watchKeys)
|
||||
}
|
||||
|
||||
func genNoPageResultParser(codeKey, msgKey, resultKey, okCode string) func(data map[string]interface{}) (interface{}, error) {
|
||||
@@ -269,7 +253,7 @@ func (a *API) AccessAPINoPage(apiStr string, jdParams map[string]interface{}, ke
|
||||
if err == nil {
|
||||
return utils.DictKeysMan(result, keyToRemove, keyToKeep), nil
|
||||
}
|
||||
err = a.rebuildError(err, jdParams)
|
||||
err = platformapi.RebuildError(err, jdParams, watchKeys)
|
||||
baseapi.SugarLogger.Infof("AccessAPINoPage failed, apiStr:%s, jdParams:%s, data:%s, error:%v", apiStr, utils.Format4Output(jdParams, true), utils.Format4Output(jsonResult, true), err)
|
||||
return result, err
|
||||
}
|
||||
@@ -367,12 +351,12 @@ func (a *API) AccessAPIHavePage(apiStr string, jdParams map[string]interface{},
|
||||
if innerCode != "0" {
|
||||
err2 := utils.NewErrorCode(getErrMsgFromData(data), innerCode, 1)
|
||||
baseapi.SugarLogger.Infof("AccessAPIHavePage failed, apiStr:%s, jdParams:%s, data:%s, error:%v", apiStr, utils.Format4Output(jdParams, true), utils.Format4Output(jsonResult, true), err2)
|
||||
return nil, totalCount, a.rebuildError(err2, jdParams)
|
||||
return nil, totalCount, platformapi.RebuildError(err2, jdParams, watchKeys)
|
||||
}
|
||||
|
||||
inResult, totalCount2, err := pageResultParser(data, totalCount)
|
||||
if err != nil {
|
||||
return nil, totalCount, a.rebuildError(err, jdParams)
|
||||
return nil, totalCount, platformapi.RebuildError(err, jdParams, watchKeys)
|
||||
}
|
||||
totalCount = totalCount2
|
||||
|
||||
|
||||
@@ -139,5 +139,10 @@ func (a *API) AccessAPI(cmd string, isGet bool, bizParams map[string]interface{}
|
||||
retVal = jsonResult1["data"]
|
||||
return platformapi.ErrLevelSuccess, nil
|
||||
})
|
||||
err = platformapi.RebuildError(err, bizParams, []string{
|
||||
KeyAppPoiCode,
|
||||
KeyAppPoiCodes,
|
||||
KeyAppFoodCode,
|
||||
})
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package platformapi
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
@@ -173,3 +174,20 @@ func AccessPlatformAPIWithRetry(client *http.Client, handleRequest func() *http.
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
func RebuildError(inErr error, bzParams map[string]interface{}, watchKeys []string) (outErr error) {
|
||||
if inErr != nil {
|
||||
if codeErr, ok := inErr.(*utils.ErrorWithCode); ok {
|
||||
appendErrList := []string{}
|
||||
for _, key := range watchKeys {
|
||||
if bzParams[key] != nil {
|
||||
appendErrList = append(appendErrList, fmt.Sprintf("[%s:%v]", key, bzParams[key]))
|
||||
}
|
||||
}
|
||||
if len(appendErrList) > 0 {
|
||||
inErr = utils.NewErrorCode(strings.Join(appendErrList, ",")+", "+codeErr.ErrMsg(), codeErr.Code())
|
||||
}
|
||||
}
|
||||
}
|
||||
return inErr
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user