- 将饿百返回的以8进制返回的错误信息显示为正常的文本
This commit is contained in:
@@ -279,6 +279,7 @@ func (a *API) SkuGetItemsByCategoryId(shopID string, categoryID int64) (skus []m
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 此函数查不到结果是不会报错的
|
||||||
func (a *API) SkuList(shopID string, params *SkuListParams) (skuInfo *PageDataInfo, err error) {
|
func (a *API) SkuList(shopID string, params *SkuListParams) (skuInfo *PageDataInfo, err error) {
|
||||||
paramMap := utils.Struct2FlatMap(params)
|
paramMap := utils.Struct2FlatMap(params)
|
||||||
paramMap[KeyShopID] = shopID
|
paramMap[KeyShopID] = shopID
|
||||||
@@ -359,14 +360,21 @@ func handleShopSkuBatchResult(result *ResponseResult) (opResult *BatchOpResult,
|
|||||||
return opResult, err
|
return opResult, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleShopSkuBatchErr(err error) (opResult *BatchOpResult) {
|
func handleShopSkuBatchErr(err error) (opResult *BatchOpResult, outErr error) {
|
||||||
if errMsg := utils.GetErrMsg(err); errMsg != "" {
|
outErr = err
|
||||||
var data interface{}
|
if errExt, ok := err.(*utils.ErrorWithCode); ok {
|
||||||
if err2 := utils.UnmarshalUseNumber([]byte(errMsg), &data); err2 == nil {
|
if errExt.ErrMsg() != "" {
|
||||||
utils.Map2StructByJson(data, &opResult, true)
|
var data interface{}
|
||||||
|
if err2 := utils.UnmarshalUseNumber([]byte(errExt.ErrMsg()), &data); err2 == nil {
|
||||||
|
if err2 = utils.Map2StructByJson(data, &opResult, true); err2 == nil {
|
||||||
|
// 将以\u表示的字符串标准化
|
||||||
|
errExt.SetErrMsg(string(utils.MustMarshal(opResult)))
|
||||||
|
outErr = errExt
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return opResult
|
return opResult, outErr
|
||||||
}
|
}
|
||||||
|
|
||||||
// 门店商品批量修改可售,价格,库存的API,在2019/07/26之前,除了SkuPriceUpdateBatch外,其它API在部分失败时会返回成功,
|
// 门店商品批量修改可售,价格,库存的API,在2019/07/26之前,除了SkuPriceUpdateBatch外,其它API在部分失败时会返回成功,
|
||||||
@@ -382,7 +390,7 @@ func (a *API) SkuDelete(shopID string, skuIDs []int64, customSkuDs []string) (op
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
opResult, err = handleShopSkuBatchResult(result)
|
opResult, err = handleShopSkuBatchResult(result)
|
||||||
} else {
|
} else {
|
||||||
opResult = handleShopSkuBatchErr(err)
|
opResult, err = handleShopSkuBatchErr(err)
|
||||||
}
|
}
|
||||||
return opResult, err
|
return opResult, err
|
||||||
}
|
}
|
||||||
@@ -394,7 +402,7 @@ func (a *API) SkuOnline(shopID string, skuIDs []int64, customSkuDs, upcs []strin
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
opResult, err = handleShopSkuBatchResult(result)
|
opResult, err = handleShopSkuBatchResult(result)
|
||||||
} else {
|
} else {
|
||||||
opResult = handleShopSkuBatchErr(err)
|
opResult, err = handleShopSkuBatchErr(err)
|
||||||
}
|
}
|
||||||
return opResult, err
|
return opResult, err
|
||||||
}
|
}
|
||||||
@@ -413,7 +421,7 @@ func (a *API) SkuOffline(shopID string, skuIDs []int64, customSkuDs, upcs []stri
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
opResult, err = handleShopSkuBatchResult(result)
|
opResult, err = handleShopSkuBatchResult(result)
|
||||||
} else {
|
} else {
|
||||||
opResult = handleShopSkuBatchErr(err)
|
opResult, err = handleShopSkuBatchErr(err)
|
||||||
}
|
}
|
||||||
return opResult, err
|
return opResult, err
|
||||||
}
|
}
|
||||||
@@ -434,7 +442,7 @@ func (a *API) SkuPriceUpdateBatch(shopID string, priceList ShopSkuInfoList, skuI
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
opResult, err = handleShopSkuBatchResult(result)
|
opResult, err = handleShopSkuBatchResult(result)
|
||||||
} else {
|
} else {
|
||||||
opResult = handleShopSkuBatchErr(err)
|
opResult, err = handleShopSkuBatchErr(err)
|
||||||
}
|
}
|
||||||
return opResult, err
|
return opResult, err
|
||||||
}
|
}
|
||||||
@@ -458,7 +466,7 @@ func (a *API) SkuStockUpdateBatch(shopID string, stockList ShopSkuInfoList, skuI
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
opResult, err = handleShopSkuBatchResult(result)
|
opResult, err = handleShopSkuBatchResult(result)
|
||||||
} else {
|
} else {
|
||||||
opResult = handleShopSkuBatchErr(err)
|
opResult, err = handleShopSkuBatchErr(err)
|
||||||
}
|
}
|
||||||
return opResult, err
|
return opResult, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,6 +59,10 @@ func (e *ErrorWithCode) ErrMsg() string {
|
|||||||
return e.errMsg
|
return e.errMsg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *ErrorWithCode) SetErrMsg(errMsg string) {
|
||||||
|
e.errMsg = errMsg
|
||||||
|
}
|
||||||
|
|
||||||
func (e *ErrorWithCode) AddPrefixMsg(prefix string) {
|
func (e *ErrorWithCode) AddPrefixMsg(prefix string) {
|
||||||
e.prefixList = append(e.prefixList, prefix)
|
e.prefixList = append(e.prefixList, prefix)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user