async function threllWithRetry(path, options, attempt = 0) {
const res = await fetch(BASE + path, withAuth(options));
if (res.status === 429 && attempt < 5) {
const wait = Math.min(2 ** attempt * 500, 8000) + Math.random() * 250;
await new Promise(r => setTimeout(r, wait));
return threllWithRetry(path, options, attempt + 1);
}
return res;
}
import random, time
def threll_with_retry(path, attempt=0, **kwargs):
res = session.request(url=BASE + path, **kwargs)
if res.status_code == 429 and attempt < 5:
wait = min(2 ** attempt * 0.5, 8.0) + random.random() * 0.25
time.sleep(wait)
return threll_with_retry(path, attempt + 1, **kwargs)
return res