From 3c7671b72f89eb417148e0021161042587aa2bd7 Mon Sep 17 00:00:00 2001 From: gazebo Date: Mon, 20 Jan 2020 09:59:32 +0800 Subject: [PATCH] ebaiapi.IsErrSkuExist, IsErrSkuNotExist --- platformapi/ebaiapi/shop_sku.go | 15 +++++++++++++-- utils/errorwithcode.go | 19 ++++++++++++------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/platformapi/ebaiapi/shop_sku.go b/platformapi/ebaiapi/shop_sku.go index ed51e200..0e60a104 100644 --- a/platformapi/ebaiapi/shop_sku.go +++ b/platformapi/ebaiapi/shop_sku.go @@ -32,6 +32,9 @@ const ( var ( shopSkuBatchFailedSkuReg = regexp.MustCompile(`请核查以下sku:(\{.*\})`) + + skuExistMsgList = []string{"商品已存在", "shop sku exist", "已被使用,请更换"} + skuNotExistMsgList = []string{"sku_id与shop_id不匹配", "SKU不存在或者已经被删除", "商品不存在"} ) type CategoryInfo struct { @@ -551,11 +554,19 @@ func IsErrCategoryNotExist(err error) (isNotExist bool) { } func IsErrSkuExist(err error) (isExist bool) { - return utils.IsErrMatch(err, "1", []string{"商品已存在", "shop sku exist", "已被使用,请更换"}) + return utils.IsErrMatch(err, "1", skuExistMsgList) } func IsErrSkuNotExist(err error) (isExist bool) { - return utils.IsErrMatch(err, "1", []string{"sku_id与shop_id不匹配", "SKU不存在或者已经被删除", "商品不存在"}) + return utils.IsErrMatch(err, "1", skuNotExistMsgList) +} + +func IsMsgSkuExist(msg string) bool { + return utils.IsErrMsgMatch(msg, skuExistMsgList) +} + +func IsMsgSkuNotExist(msg string) bool { + return utils.IsErrMsgMatch(msg, skuNotExistMsgList) } func (a *API) GetEbaiSkuIDFromCustomID(shopID, customSkuID string) (ebaiSkuID int64) { diff --git a/utils/errorwithcode.go b/utils/errorwithcode.go index b42da06f..27f26d77 100644 --- a/utils/errorwithcode.go +++ b/utils/errorwithcode.go @@ -71,19 +71,24 @@ func IsErrMatch(err error, strCode string, strList []string) (isMatch bool) { if err != nil { if codeErr, ok := err.(*ErrorWithCode); ok { if strCode == "" || codeErr.Code() == strCode { - isMatch = len(strList) == 0 - for _, v := range strList { - if strings.Index(codeErr.ErrMsg(), v) >= 0 { - isMatch = true - break - } - } + isMatch = IsErrMsgMatch(codeErr.ErrMsg(), strList) } } } return isMatch } +func IsErrMsgMatch(errMsg string, strList []string) (isMatch bool) { + isMatch = len(strList) == 0 + for _, v := range strList { + if strings.Index(errMsg, v) >= 0 { + isMatch = true + break + } + } + return isMatch +} + func GetErrMsg(err error) (errMsg string) { if errExt, ok := err.(*ErrorWithCode); ok { errMsg = errExt.ErrMsg()