- GetJdSkuIDFromError

This commit is contained in:
gazebo
2019-04-25 08:41:24 +08:00
parent b05fdc63a5
commit 1d6dabdccc

View File

@@ -2,6 +2,8 @@ package jdapi
import (
"fmt"
"regexp"
"strings"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/globals"
@@ -129,6 +131,10 @@ type CreateByUpcPair struct {
SkuId int64
}
var (
skuExistReg = regexp.MustCompile(`商家skuId已存在:(\d+)`)
)
// 分页查询商品品牌信息接口
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=180&apiid=1ca07a3e767649a7a44fc6ea7e9ed8dd
func (a *API) QueryPageBrandInfo(pageNo, pageSize, brandId int, brandName string) (brandList []*BrandInfo, totalCount int, err error) {
@@ -646,3 +652,13 @@ func genAttrMapList(kgAttr string) (attrList []map[string]interface{}) {
},
}
}
func GetJdSkuIDFromError(err error) int64 {
if err2, ok := err.(*utils.ErrorWithCode); ok && err2.IntCode() == 11001 && strings.Index(err2.ErrMsg(), "商家skuId已存在") >= 0 {
searchResult := skuExistReg.FindStringSubmatch(err2.ErrMsg())
if searchResult != nil && len(searchResult[1]) > 0 {
return utils.Str2Int64(searchResult[1])
}
}
return 0
}