diff --git a/pkg/feeds/maven/maven.go b/pkg/feeds/maven/maven.go index de3409b1..35d7f1e1 100644 --- a/pkg/feeds/maven/maven.go +++ b/pkg/feeds/maven/maven.go @@ -3,6 +3,7 @@ package maven import ( "bytes" "encoding/json" + "errors" "fmt" "net/http" "time" @@ -72,6 +73,18 @@ func (feed Feed) fetchPackages(page int) ([]Package, error) { } defer resp.Body.Close() + // Handle rate limiting (HTTP status code 429). + if resp.StatusCode == http.StatusTooManyRequests { + time.Sleep(5 * time.Second) + return feed.fetchPackages(page) // Retry the request + } + + // Handle other HTTP status codes + if resp.StatusCode != http.StatusOK { + newErr := errors.New("unexpected HTTP status code") + return nil, fmt.Errorf("%w", newErr) + } + // Decode response. var response Response err = json.NewDecoder(resp.Body).Decode(&response)