Skip to content

Commit

Permalink
add error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
yrobla committed Feb 19, 2024
1 parent eb5ba88 commit 22af15e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/feeds/maven/maven.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ 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 {
return nil, fmt.Errorf("unexpected HTTP status code: %d", resp.StatusCode)

Check failure on line 83 in pkg/feeds/maven/maven.go

View workflow job for this annotation

GitHub Actions / build-verify

err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"unexpected HTTP status code: %d\", resp.StatusCode)" (goerr113)

Check failure on line 83 in pkg/feeds/maven/maven.go

View workflow job for this annotation

GitHub Actions / build-verify

err113: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(\"unexpected HTTP status code: %d\", resp.StatusCode)" (goerr113)
}

// Decode response.
var response Response
err = json.NewDecoder(resp.Body).Decode(&response)
Expand Down

0 comments on commit 22af15e

Please sign in to comment.