condition for additional attempts to send a request
This commit is contained in:
parent
e3281a1ee1
commit
f278b73de0
@ -68,6 +68,11 @@ func makeRequest(reqType, url string, buf io.Reader, c *MgClient) ([]byte, int,
|
|||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("X-Transport-Token", c.Token)
|
req.Header.Set("X-Transport-Token", c.Token)
|
||||||
|
|
||||||
|
maxAttempt := 1
|
||||||
|
if c.limiter != nil && c.Token != "" {
|
||||||
|
maxAttempt = 3
|
||||||
|
}
|
||||||
|
|
||||||
attempt := 0
|
attempt := 0
|
||||||
tryAgain:
|
tryAgain:
|
||||||
c.WaitForRateLimit()
|
c.WaitForRateLimit()
|
||||||
@ -84,7 +89,7 @@ tryAgain:
|
|||||||
return res, 0, NewCriticalHTTPError(err)
|
return res, 0, NewCriticalHTTPError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode == http.StatusTooManyRequests && attempt < 3 {
|
if resp.StatusCode == http.StatusTooManyRequests && attempt < maxAttempt {
|
||||||
attempt++
|
attempt++
|
||||||
c.writeLog("MG TRANSPORT API Request rate limit hit on attempt %d, retrying", attempt)
|
c.writeLog("MG TRANSPORT API Request rate limit hit on attempt %d, retrying", attempt)
|
||||||
goto tryAgain
|
goto tryAgain
|
||||||
|
Loading…
Reference in New Issue
Block a user