Skip to content

Commit

Permalink
fix: backoff function error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrosca-snyk committed Jan 8, 2025
1 parent 7d69dae commit 15938c5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/snyk/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,15 @@ func GetPackageVulnerabilities(cfg *Config, purl *packageurl.PackageURL, auth *s
func getRetryClient(logger *zerolog.Logger) *http.Client {
rc := retryablehttp.NewClient()
rc.Logger = nil
rc.ErrorHandler = retryablehttp.PassthroughErrorHandler
rc.Backoff = func(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
if sleep, ok := parseRateLimitHeader(resp.Header.Get("X-RateLimit-Reset")); ok {
logger.Warn().
Dur("Retry-After", sleep).
Msg("Getting rate-limited, waiting...")
return sleep
if resp != nil {
if sleep, ok := parseRateLimitHeader(resp.Header.Get("X-RateLimit-Reset")); ok {
logger.Warn().
Dur("Retry-After", sleep).
Msg("Getting rate-limited, waiting...")
return sleep
}
}
return retryablehttp.DefaultBackoff(min, max, attemptNum, resp)
}
Expand Down

0 comments on commit 15938c5

Please sign in to comment.