Skip to content

Commit

Permalink
fix(rate-limit): do not overwrite httpAgent on retries (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
Phoebe Schmidt authored Apr 24, 2019
1 parent 904791b commit 4f78471
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/rate-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ export default function rateLimit (instance, defaults, maxRetry = 5) {
// convert to ms and add jitter
wait = Math.floor(wait * 1000 + (Math.random() * 200) + 500)
instanceDefaults.logHandler('warning', `${retryErrorType} error occurred. Waiting for ${wait} ms before retrying...`)

/* Somehow between the interceptor and retrying the request the httpAgent/httpsAgent gets transformed from an Agent-like object
to a regular object, causing failures on retries after rate limits. Removing these properties here fixes the error, but retry
requests still use the original http/httpsAgent property */
delete config.httpAgent
delete config.httpsAgent

return delay(wait).then(() => instance(config))
}
return Promise.reject(error)
Expand Down

0 comments on commit 4f78471

Please sign in to comment.