Skip to content

Commit a834022

Browse files
committed
add error handling
1 parent eb5ba88 commit a834022

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

pkg/feeds/maven/maven.go

+11
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ func (feed Feed) fetchPackages(page int) ([]Package, error) {
7272
}
7373
defer resp.Body.Close()
7474

75+
// Handle rate limiting (HTTP status code 429).
76+
if resp.StatusCode == http.StatusTooManyRequests {
77+
time.Sleep(5 * time.Second)
78+
return feed.fetchPackages(page) // Retry the request
79+
}
80+
81+
// Handle other HTTP status codes
82+
if resp.StatusCode != http.StatusOK {
83+
return nil, fmt.Errorf("unexpected HTTP status code")
84+
}
85+
7586
// Decode response.
7687
var response Response
7788
err = json.NewDecoder(resp.Body).Decode(&response)

0 commit comments

Comments
 (0)