- refactor, remove unnecessary log.

This commit is contained in:
gazebo
2018-07-22 16:27:21 +08:00
parent 0bab97ed2a
commit cc043b7009
7 changed files with 7 additions and 26 deletions

View File

@@ -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 {

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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) {

View File

@@ -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
}
}

View File

@@ -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