From 1d6dabdcccb3e6e5ab230b7b1ef074a1871025b4 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 25 Apr 2019 08:41:24 +0800 Subject: [PATCH] - GetJdSkuIDFromError --- platformapi/jdapi/sku.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/platformapi/jdapi/sku.go b/platformapi/jdapi/sku.go index 42228100..22214dab 100644 --- a/platformapi/jdapi/sku.go +++ b/platformapi/jdapi/sku.go @@ -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 +}