- try to append shop info in err msg when ebai api failed.
This commit is contained in:
@@ -127,5 +127,21 @@ func (a *API) AccessAPI(cmd string, body map[string]interface{}) (retVal *Respon
|
|||||||
}
|
}
|
||||||
return platformapi.ErrLevelCodeIsNotOK, newErr
|
return platformapi.ErrLevelCodeIsNotOK, newErr
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
if codeErr, ok := err.(*utils.ErrorWithCode); ok {
|
||||||
|
if body[KeyBaiduShopID] != nil || body[KeyShopID] != nil {
|
||||||
|
shopInfoList := []string{}
|
||||||
|
for _, key := range []string{
|
||||||
|
KeyBaiduShopID,
|
||||||
|
KeyShopID,
|
||||||
|
} {
|
||||||
|
if body[key] != nil {
|
||||||
|
shopInfoList = append(shopInfoList, fmt.Sprintf("[%s:%v]", key, body[key]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err = utils.NewErrorCode(strings.Join(shopInfoList, ",")+", "+codeErr.ErrMsg(), codeErr.Code())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return retVal, err
|
return retVal, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,15 +7,15 @@ import (
|
|||||||
|
|
||||||
type ErrorWithCode struct {
|
type ErrorWithCode struct {
|
||||||
level int
|
level int
|
||||||
str string
|
errMsg string
|
||||||
code string
|
code string
|
||||||
intCode int
|
intCode int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewErrorCode(err, code string, level ...int) *ErrorWithCode {
|
func NewErrorCode(errMsg, code string, level ...int) *ErrorWithCode {
|
||||||
retVal := &ErrorWithCode{
|
retVal := &ErrorWithCode{
|
||||||
str: err,
|
errMsg: errMsg,
|
||||||
code: code,
|
code: code,
|
||||||
}
|
}
|
||||||
retVal.intCode, _ = strconv.Atoi(code)
|
retVal.intCode, _ = strconv.Atoi(code)
|
||||||
if len(level) > 0 {
|
if len(level) > 0 {
|
||||||
@@ -25,12 +25,12 @@ func NewErrorCode(err, code string, level ...int) *ErrorWithCode {
|
|||||||
return retVal
|
return retVal
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewErrorIntCode(err string, code int, level ...int) *ErrorWithCode {
|
func NewErrorIntCode(errMsg string, code int, level ...int) *ErrorWithCode {
|
||||||
return NewErrorCode(err, Int2Str(code), level...)
|
return NewErrorCode(errMsg, Int2Str(code), level...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ErrorWithCode) Error() string {
|
func (e *ErrorWithCode) Error() string {
|
||||||
return fmt.Sprintf("%s level:%d, code:%s", e.str, e.level, e.code)
|
return fmt.Sprintf("%s level:%d, code:%s", e.errMsg, e.level, e.code)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ErrorWithCode) String() string {
|
func (e *ErrorWithCode) String() string {
|
||||||
@@ -48,3 +48,7 @@ func (e *ErrorWithCode) Code() string {
|
|||||||
func (e *ErrorWithCode) IntCode() int {
|
func (e *ErrorWithCode) IntCode() int {
|
||||||
return e.intCode
|
return e.intCode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *ErrorWithCode) ErrMsg() string {
|
||||||
|
return e.errMsg
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user