1
0
mirror of synced 2024-11-24 05:56:04 +03:00

condition for additional attempts to send a request

This commit is contained in:
Суханов Данила 2024-02-16 09:28:35 +03:00
parent e3281a1ee1
commit f278b73de0

View File

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