Skip to content

Commit

Permalink
feat: log unexpected status codes in the retryable client (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrosca-snyk authored Jan 9, 2025
1 parent a2115ef commit cdc9a13
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/snyk/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ func getRetryClient(logger *zerolog.Logger) *http.Client {
rc := retryablehttp.NewClient()
rc.Logger = nil
rc.ErrorHandler = retryablehttp.PassthroughErrorHandler
rc.ResponseLogHook = func(_ retryablehttp.Logger, r *http.Response) {
if r != nil && r.StatusCode >= 400 {
logger.Warn().Msgf("Unexpected status code (%s) for %s %s", r.Status, r.Request.Method, r.Request.URL.String())
}
}
rc.Backoff = func(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
if resp != nil {
if sleep, ok := parseRateLimitHeader(resp.Header.Get("X-RateLimit-Reset")); ok {
Expand Down

0 comments on commit cdc9a13

Please sign in to comment.