ebaiapi.IsErrSkuExist, IsErrSkuNotExist
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user