Skip to content

Commit

Permalink
FIX: retryRequest.js
Browse files Browse the repository at this point in the history
  • Loading branch information
dwhieb committed Jul 25, 2024
1 parent 9f58608 commit d4b4f66
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions data/utilities/retryRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,28 @@ export default function retryRequest(requestFunction, ...args) {
let waitTime = 1

const request = async () => {

let ret

try {

return requestFunction(...args)
ret = await requestFunction(...args)

} catch (e) {

if (e.response?.status == 429) {
if (e.response.status == 429) {
waitTime *= 2
console.warn(`\nHit rate limit. Retrying after ${ waitTime }ms.`)
await setTimeout(waitTime)
return request()
ret = await request()
} else {
throw e
}

throw e

}

return ret

}

return request()
Expand Down

0 comments on commit d4b4f66

Please sign in to comment.