Improved retries

Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
This commit is contained in:
2025-05-07 06:37:59 +01:00
parent c29e828d23
commit fa72756aaf
2 changed files with 2 additions and 1 deletions

View File

@@ -110,7 +110,7 @@ func GetLatestBooks() (map[string]*Book, error) {
func getRating(bookID string) string { func getRating(bookID string) string {
resp, err := c.Get(fmt.Sprintf("https://app.thestorygraph.com/books/%s/community_reviews", bookID)) resp, err := c.Get(fmt.Sprintf("https://app.thestorygraph.com/books/%s/community_reviews", bookID))
if err != nil { if err != nil {
fmt.Println("Error fetching book rating:", resp.StatusCode) fmt.Println("Error fetching book rating:", err)
return "0.0" return "0.0"
} }
defer resp.Body.Close() defer resp.Body.Close()

View File

@@ -52,6 +52,7 @@ func (h *HTTPClient) Get(url string) (*http.Response, error) {
if resp.StatusCode == 429 { if resp.StatusCode == 429 {
fmt.Println("Rate limit exceeded, retrying...") fmt.Println("Rate limit exceeded, retrying...")
h.retries-- h.retries--
time.Sleep(30 * time.Second)
continue continue
} }