- 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" "sort"
"strings" "strings"
"git.rosy.net.cn/baseapi"
"git.rosy.net.cn/baseapi/platformapi" "git.rosy.net.cn/baseapi/platformapi"
"git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/baseapi/utils"
) )
@@ -111,7 +110,6 @@ func (a *API) AccessAPI(apiStr string, params map[string]interface{}) (retVal Re
retVal = jsonResult1 retVal = jsonResult1
return platformapi.ErrLevelSuccess, nil return platformapi.ErrLevelSuccess, nil
} }
baseapi.SugarLogger.Warnf("response business code is not ok, data:%v, status:%v", jsonResult1, status)
infoCode := jsonResult1["infocode"].(string) infoCode := jsonResult1["infocode"].(string)
newErr := utils.NewErrorCode(jsonResult1["info"].(string), infoCode) newErr := utils.NewErrorCode(jsonResult1["info"].(string), infoCode)
if _, ok := exceedLimitCodes[infoCode]; ok { if _, ok := exceedLimitCodes[infoCode]; ok {

View File

@@ -7,7 +7,6 @@ import (
"net/http" "net/http"
"sort" "sort"
"git.rosy.net.cn/baseapi"
"git.rosy.net.cn/baseapi/platformapi" "git.rosy.net.cn/baseapi/platformapi"
"git.rosy.net.cn/baseapi/utils" "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"] retVal.Result = jsonResult1["result"]
return platformapi.ErrLevelSuccess, nil 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) newErr := utils.NewErrorIntCode(retVal.Msg, code)
if code == ResponseCodeRetryLater || code == ResponseCodeNetworkErr { if code == ResponseCodeRetryLater || code == ResponseCodeNetworkErr {
return platformapi.ErrLevelRecoverableErr, newErr return platformapi.ErrLevelRecoverableErr, newErr

View File

@@ -10,7 +10,6 @@ import (
"strings" "strings"
"sync" "sync"
"git.rosy.net.cn/baseapi"
"git.rosy.net.cn/baseapi/platformapi" "git.rosy.net.cn/baseapi/platformapi"
"git.rosy.net.cn/baseapi/utils" "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 return platformapi.ErrLevelSuccess, nil
} }
code := errinfoMap["code"].(string) 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) newErr := utils.NewErrorCode(errinfoMap["message"].(string), code)
if code == "EXCEED_LIMIT" { if code == "EXCEED_LIMIT" {
return platformapi.ErrLevelExceedLimit, newErr return platformapi.ErrLevelExceedLimit, newErr

View File

@@ -64,7 +64,6 @@ var (
ResponseCodeExceedLimit: 1, ResponseCodeExceedLimit: 1,
} }
// todo replace all magic number
canRetryCodes = map[string]int{ canRetryCodes = map[string]int{
ResponseCodeFailedCanAutoRetry: 1, ResponseCodeFailedCanAutoRetry: 1,
ResponseCodeAccessFailed: 1, ResponseCodeAccessFailed: 1,
@@ -155,7 +154,6 @@ func (a *API) AccessAPI(apiStr string, jdParams map[string]interface{}) (retVal
retVal = jsonResult1 retVal = jsonResult1
return platformapi.ErrLevelSuccess, nil 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) newErr := utils.NewErrorCode(jsonResult1["msg"].(string), code)
if _, ok := exceedLimitCodes[code]; ok { if _, ok := exceedLimitCodes[code]; ok {
return platformapi.ErrLevelExceedLimit, newErr return platformapi.ErrLevelExceedLimit, newErr

View File

@@ -11,7 +11,6 @@ import (
"github.com/fatih/structs" "github.com/fatih/structs"
"git.rosy.net.cn/baseapi"
"git.rosy.net.cn/baseapi/platformapi" "git.rosy.net.cn/baseapi/platformapi"
"git.rosy.net.cn/baseapi/utils" "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 return platformapi.ErrLevelSuccess, nil
} }
baseapi.SugarLogger.Warnf("response business code is not ok, data:%v, code:%v", jsonResult1, code)
retVal.Message = jsonResult1["message"].(string) retVal.Message = jsonResult1["message"].(string)
newErr := utils.NewErrorIntCode(retVal.Message, code) newErr := utils.NewErrorIntCode(retVal.Message, code)
return platformapi.ErrLevelCodeIsNotOK, newErr return platformapi.ErrLevelCodeIsNotOK, newErr
@@ -264,12 +262,10 @@ func (a *API) CancelOrder(deliveryId int64, mtPeiSongId string, cancelReasonId i
"cancel_reason": cancelReason, "cancel_reason": cancelReason,
} }
if result, err := a.AccessAPI("order/delete", params); err != nil { if result, err := a.AccessAPI("order/delete", params); err != nil {
baseapi.SugarLogger.Debugf("result:%v", result)
return nil, err return nil, err
} else { } else {
return a.result2OrderResponse(result), nil return a.result2OrderResponse(result), nil
} }
} }
func (a *API) simulateOrderBehavior(action string, deliveryId int64, mtPeiSongId string) (err error) { func (a *API) simulateOrderBehavior(action string, deliveryId int64, mtPeiSongId string) (err error) {

View File

@@ -58,8 +58,6 @@ const (
var ( var (
ErrAPIAccessFailed = errors.New("access API failed") ErrAPIAccessFailed = errors.New("access API failed")
ErrHTTPCodeIsNot200 = errors.New("HTTP code is not 200") 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") ErrResponseDataFormatWrong = errors.New("the data of response has wrong format")
) )
@@ -80,22 +78,21 @@ func AccessPlatformAPIWithRetry(client *http.Client, request *http.Request, conf
for { for {
response, err := client.Do(request) response, err := client.Do(request)
if err != nil { 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) err, ok := err.(net.Error)
recoverableErrorRetryCount++ recoverableErrorRetryCount++
if ok && err.Timeout() && recoverableErrorRetryCount <= config.MaxRecoverableRetryCount { if ok && err.Timeout() && recoverableErrorRetryCount <= config.MaxRecoverableRetryCount {
continue continue
} else { } 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 return ErrAPIAccessFailed
} }
} }
defer response.Body.Close() defer response.Body.Close()
if response.StatusCode != 200 { 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 return ErrHTTPCodeIsNot200
} }
errLevel, err := handleResponse(response) errLevel, err := handleResponse(response)
if err == nil { if err == nil {
return nil return nil
@@ -104,16 +101,14 @@ func AccessPlatformAPIWithRetry(client *http.Client, request *http.Request, conf
if exceedLimitRetryCount <= config.MaxExceedLimitRetryCount { if exceedLimitRetryCount <= config.MaxExceedLimitRetryCount {
time.Sleep(config.SleepSecondWhenExceedLimit) time.Sleep(config.SleepSecondWhenExceedLimit)
continue continue
} else {
return ErrLimitExceedReachMaxRetry
} }
} else if errLevel == ErrLevelRecoverableErr { } else if errLevel == ErrLevelRecoverableErr {
recoverableErrorRetryCount++ recoverableErrorRetryCount++
if recoverableErrorRetryCount <= config.MaxRecoverableRetryCount { if recoverableErrorRetryCount <= config.MaxRecoverableRetryCount {
continue continue
} }
return err
} }
baseapi.SugarLogger.Infof("AccessPlatformAPIWithRetry failed, error:%v", err)
return err return err
} }
} }

View File

@@ -5,7 +5,6 @@ import (
"strings" "strings"
"sync" "sync"
"git.rosy.net.cn/baseapi"
"git.rosy.net.cn/baseapi/platformapi" "git.rosy.net.cn/baseapi/platformapi"
"git.rosy.net.cn/baseapi/utils" "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 { if retVal != nil {
return platformapi.ErrLevelSuccess, 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) newErr := utils.NewErrorIntCode(errInfo.ErrMsg, errInfo.ErrCode)
if errInfo.ErrCode == ResponseCodeBusy { if errInfo.ErrCode == ResponseCodeBusy {
return platformapi.ErrLevelRecoverableErr, newErr return platformapi.ErrLevelRecoverableErr, newErr