Update index.ts

This commit is contained in:
Daniel Hougaard
2025-04-16 23:54:14 +04:00
parent 48ccf7a73a
commit 71bc65c293

View File

@@ -29,7 +29,6 @@ const setupAxiosRetry = () => {
const maxRetries = 4; const maxRetries = 4;
const initialRetryDelay = 1000; const initialRetryDelay = 1000;
const backoffFactor = 2; const backoffFactor = 2;
axiosInstance.interceptors.response.use(null, (error: AxiosError) => { axiosInstance.interceptors.response.use(null, (error: AxiosError) => {
@@ -44,7 +43,9 @@ const setupAxiosRetry = () => {
// handle rate limits and network errors // handle rate limits and network errors
if ((error.response?.status === 429 || error.response?.status === undefined) && config && config._retryCount! < maxRetries) { if ((error.response?.status === 429 || error.response?.status === undefined) && config && config._retryCount! < maxRetries) {
config._retryCount!++; config._retryCount!++;
const exponentialDelay = Math.min(initialRetryDelay * Math.pow(backoffFactor, config._retryCount! - 1)); const baseDelay = initialRetryDelay * Math.pow(backoffFactor, config._retryCount! - 1);
const jitter = baseDelay * 0.2; // 20% +/- jitter
const exponentialDelay = Math.min(baseDelay + (Math.random() * 2 - 1) * jitter);
return new Promise(resolve => { return new Promise(resolve => {
setTimeout(() => { setTimeout(() => {