- refactor platformapi.AccessPlatformAPIWithRetry

This commit is contained in:
gazebo
2019-01-12 14:04:37 +08:00
parent fc34194835
commit e124038aa2
11 changed files with 20 additions and 56 deletions

View File

@@ -10,6 +10,7 @@ import (
"time"
"git.rosy.net.cn/baseapi"
"git.rosy.net.cn/baseapi/utils"
"github.com/fatih/structs"
)
@@ -79,7 +80,7 @@ func getClonedData(r *bytes.Buffer) string {
return string(r.Bytes())
}
func AccessPlatformAPIWithRetry(client *http.Client, handleRequest func() *http.Request, config *APIConfig, handleResponse func(response *http.Response) (string, error)) error {
func AccessPlatformAPIWithRetry(client *http.Client, handleRequest func() *http.Request, config *APIConfig, handleResponse func(bodyMap map[string]interface{}) (string, error)) error {
exceedLimitRetryCount := 0
recoverableErrorRetryCount := 0
for {
@@ -116,7 +117,13 @@ func AccessPlatformAPIWithRetry(client *http.Client, handleRequest func() *http.
}
return ErrHTTPCodeIsNot200
}
errLevel, err := handleResponse(response)
var errLevel string
bodyMap, err := utils.HTTPResponse2Json(response)
if err != nil {
errLevel = ErrLevelRecoverableErr
} else {
errLevel, err = handleResponse(bodyMap)
}
if err == nil {
return nil
} else if errLevel == ErrLevelExceedLimit {