- refactor platformapi.AccessPlatformAPIWithRetry
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user