From f278b73de033f6b96ea827014631acfecd130a20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=83=D1=85=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=BB=D0=B0?= Date: Fri, 16 Feb 2024 09:28:35 +0300 Subject: [PATCH] condition for additional attempts to send a request --- v1/request.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/v1/request.go b/v1/request.go index 74bc0d1..571b375 100644 --- a/v1/request.go +++ b/v1/request.go @@ -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("X-Transport-Token", c.Token) + maxAttempt := 1 + if c.limiter != nil && c.Token != "" { + maxAttempt = 3 + } + attempt := 0 tryAgain: c.WaitForRateLimit() @@ -84,7 +89,7 @@ tryAgain: return res, 0, NewCriticalHTTPError(err) } - if resp.StatusCode == http.StatusTooManyRequests && attempt < 3 { + if resp.StatusCode == http.StatusTooManyRequests && attempt < maxAttempt { attempt++ c.writeLog("MG TRANSPORT API Request rate limit hit on attempt %d, retrying", attempt) goto tryAgain