Skip to content

Commit 7ab6671

Browse files
authored
Add HTTP retry for 429 (#55)
* (feat) add retry for 429s
1 parent a079b58 commit 7ab6671

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

internal/api/client.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"net/http"
1010
"net/url"
1111
"path"
12+
"time"
1213
)
1314

1415
type APIClientConfig struct {
@@ -65,6 +66,13 @@ func (c *Client) Request(method, endpoint string, query, data, response interfac
6566
}
6667
defer res.Body.Close()
6768

69+
// Retry in case backend responds with HTTP 429
70+
// sleep for 3 seconds before retry
71+
if res.StatusCode == 429 {
72+
time.Sleep(3 * time.Second)
73+
return c.Request(method, endpoint, query, data, &response)
74+
}
75+
6876
if res.StatusCode != http.StatusOK {
6977
return fmt.Errorf("Non-OK status: %d", res.StatusCode)
7078
}

0 commit comments

Comments
 (0)