diff --git a/platformapi/autonavi/autonavi.go b/platformapi/autonavi/autonavi.go index 4d0baeae..0a26dd7b 100644 --- a/platformapi/autonavi/autonavi.go +++ b/platformapi/autonavi/autonavi.go @@ -7,7 +7,6 @@ import ( "sort" "strings" - "git.rosy.net.cn/baseapi" "git.rosy.net.cn/baseapi/platformapi" "git.rosy.net.cn/baseapi/utils" ) @@ -111,7 +110,6 @@ func (a *API) AccessAPI(apiStr string, params map[string]interface{}) (retVal Re retVal = jsonResult1 return platformapi.ErrLevelSuccess, nil } - baseapi.SugarLogger.Warnf("response business code is not ok, data:%v, status:%v", jsonResult1, status) infoCode := jsonResult1["infocode"].(string) newErr := utils.NewErrorCode(jsonResult1["info"].(string), infoCode) if _, ok := exceedLimitCodes[infoCode]; ok { diff --git a/platformapi/dadaapi/dadaapi.go b/platformapi/dadaapi/dadaapi.go index a1b61e56..f6f2f872 100644 --- a/platformapi/dadaapi/dadaapi.go +++ b/platformapi/dadaapi/dadaapi.go @@ -7,7 +7,6 @@ import ( "net/http" "sort" - "git.rosy.net.cn/baseapi" "git.rosy.net.cn/baseapi/platformapi" "git.rosy.net.cn/baseapi/utils" ) @@ -128,7 +127,6 @@ func (a *API) AccessAPI(action string, params map[string]interface{}) (retVal *R retVal.Result = jsonResult1["result"] return platformapi.ErrLevelSuccess, nil } - baseapi.SugarLogger.Warnf("response business code is not ok, data:%v, code:%v", jsonResult1, code) newErr := utils.NewErrorIntCode(retVal.Msg, code) if code == ResponseCodeRetryLater || code == ResponseCodeNetworkErr { return platformapi.ErrLevelRecoverableErr, newErr diff --git a/platformapi/elmapi/elmapi.go b/platformapi/elmapi/elmapi.go index 6ed6686d..a60220b0 100644 --- a/platformapi/elmapi/elmapi.go +++ b/platformapi/elmapi/elmapi.go @@ -10,7 +10,6 @@ import ( "strings" "sync" - "git.rosy.net.cn/baseapi" "git.rosy.net.cn/baseapi/platformapi" "git.rosy.net.cn/baseapi/utils" ) @@ -168,7 +167,6 @@ func (a *API) AccessAPI(action string, params map[string]interface{}) (retVal *R return platformapi.ErrLevelSuccess, nil } code := errinfoMap["code"].(string) - baseapi.SugarLogger.Warnf("response business code is not ok, data:%v, code:%v, bodyStr:%v", jsonResult1, code, bodyStr) newErr := utils.NewErrorCode(errinfoMap["message"].(string), code) if code == "EXCEED_LIMIT" { return platformapi.ErrLevelExceedLimit, newErr diff --git a/platformapi/jdapi/jdapi.go b/platformapi/jdapi/jdapi.go index f20052df..42e6b299 100644 --- a/platformapi/jdapi/jdapi.go +++ b/platformapi/jdapi/jdapi.go @@ -64,7 +64,6 @@ var ( ResponseCodeExceedLimit: 1, } - // todo replace all magic number canRetryCodes = map[string]int{ ResponseCodeFailedCanAutoRetry: 1, ResponseCodeAccessFailed: 1, @@ -155,7 +154,6 @@ func (a *API) AccessAPI(apiStr string, jdParams map[string]interface{}) (retVal retVal = jsonResult1 return platformapi.ErrLevelSuccess, nil } - baseapi.SugarLogger.Warnf("response business code is not ok, data:%v, code:%v", jsonResult1, code) newErr := utils.NewErrorCode(jsonResult1["msg"].(string), code) if _, ok := exceedLimitCodes[code]; ok { return platformapi.ErrLevelExceedLimit, newErr diff --git a/platformapi/mtpsapi/mtpsapi.go b/platformapi/mtpsapi/mtpsapi.go index 7d3184b3..c626a76b 100644 --- a/platformapi/mtpsapi/mtpsapi.go +++ b/platformapi/mtpsapi/mtpsapi.go @@ -11,7 +11,6 @@ import ( "github.com/fatih/structs" - "git.rosy.net.cn/baseapi" "git.rosy.net.cn/baseapi/platformapi" "git.rosy.net.cn/baseapi/utils" ) @@ -212,7 +211,6 @@ func (a *API) AccessAPI(action string, params map[string]interface{}) (retVal *R } return platformapi.ErrLevelSuccess, nil } - baseapi.SugarLogger.Warnf("response business code is not ok, data:%v, code:%v", jsonResult1, code) retVal.Message = jsonResult1["message"].(string) newErr := utils.NewErrorIntCode(retVal.Message, code) return platformapi.ErrLevelCodeIsNotOK, newErr @@ -264,12 +262,10 @@ func (a *API) CancelOrder(deliveryId int64, mtPeiSongId string, cancelReasonId i "cancel_reason": cancelReason, } if result, err := a.AccessAPI("order/delete", params); err != nil { - baseapi.SugarLogger.Debugf("result:%v", result) return nil, err } else { return a.result2OrderResponse(result), nil } - } func (a *API) simulateOrderBehavior(action string, deliveryId int64, mtPeiSongId string) (err error) { diff --git a/platformapi/platformapi.go b/platformapi/platformapi.go index 9b5ed44b..017c176a 100644 --- a/platformapi/platformapi.go +++ b/platformapi/platformapi.go @@ -56,11 +56,9 @@ const ( // common api access error var ( - ErrAPIAccessFailed = errors.New("access API failed") - ErrHTTPCodeIsNot200 = errors.New("HTTP code is not 200") - ErrRecoverableErrReachMaxRetry = errors.New("recoverable error reach max retry count") - ErrLimitExceedReachMaxRetry = errors.New("limit exceed reach max retry count") - ErrResponseDataFormatWrong = errors.New("the data of response has wrong format") + ErrAPIAccessFailed = errors.New("access API failed") + ErrHTTPCodeIsNot200 = errors.New("HTTP code is not 200") + ErrResponseDataFormatWrong = errors.New("the data of response has wrong format") ) // common callback response @@ -80,22 +78,21 @@ func AccessPlatformAPIWithRetry(client *http.Client, request *http.Request, conf for { response, err := client.Do(request) if err != nil { - baseapi.SugarLogger.Debugf("client.Get return err:%v", err) + baseapi.SugarLogger.Debugf("AccessPlatformAPIWithRetry client.Get return err:%v", err) err, ok := err.(net.Error) recoverableErrorRetryCount++ if ok && err.Timeout() && recoverableErrorRetryCount <= config.MaxRecoverableRetryCount { continue } else { - baseapi.SugarLogger.Errorf("access api error:%v, request:%v", err, request) + baseapi.SugarLogger.Errorf("AccessPlatformAPIWithRetry access api request:%v, error:%v", request, err) return ErrAPIAccessFailed } } defer response.Body.Close() if response.StatusCode != 200 { - baseapi.SugarLogger.Errorf("HTTP code not 200, it's:%v, request:%v", response.StatusCode, request) + baseapi.SugarLogger.Errorf("AccessPlatformAPIWithRetry HTTP code is:%d, request:%v", response.StatusCode, request) return ErrHTTPCodeIsNot200 } - errLevel, err := handleResponse(response) if err == nil { return nil @@ -104,16 +101,14 @@ func AccessPlatformAPIWithRetry(client *http.Client, request *http.Request, conf if exceedLimitRetryCount <= config.MaxExceedLimitRetryCount { time.Sleep(config.SleepSecondWhenExceedLimit) continue - } else { - return ErrLimitExceedReachMaxRetry } } else if errLevel == ErrLevelRecoverableErr { recoverableErrorRetryCount++ if recoverableErrorRetryCount <= config.MaxRecoverableRetryCount { continue } - return err } + baseapi.SugarLogger.Infof("AccessPlatformAPIWithRetry failed, error:%v", err) return err } } diff --git a/platformapi/weixinapi/weixinapi.go b/platformapi/weixinapi/weixinapi.go index b4dee4bd..8cff1d5c 100644 --- a/platformapi/weixinapi/weixinapi.go +++ b/platformapi/weixinapi/weixinapi.go @@ -5,7 +5,6 @@ import ( "strings" "sync" - "git.rosy.net.cn/baseapi" "git.rosy.net.cn/baseapi/platformapi" "git.rosy.net.cn/baseapi/utils" ) @@ -119,7 +118,6 @@ func (a *API) AccessAPI(action string, params map[string]interface{}, body strin if retVal != nil { return platformapi.ErrLevelSuccess, nil } - baseapi.SugarLogger.Warnf("response business code is not ok, data:%v, code:%v", jsonResult1, errInfo.ErrCode) newErr := utils.NewErrorIntCode(errInfo.ErrMsg, errInfo.ErrCode) if errInfo.ErrCode == ResponseCodeBusy { return platformapi.ErrLevelRecoverableErr, newErr