async function e(e,t,n={}){let{timeout:r=5e3,maxRetries:i=10,retryDelay:a=1e3}=n,o=null;for(let n=0;n<i;n++){let s=new AbortController,c=setTimeout(()=>{s.abort()},r);try{let r=await fetch(e,{...t,signal:s.signal});if(clearTimeout(c),r.ok)return r;if(r.status===429||r.status>=500){let e=a+n**2*50;await new Promise(t=>setTimeout(t,e));continue}if(r.status===403)throw Error(`Unauthorized`);if(!r.ok){let e;try{e=(await r.json()).error||`HTTP error ${r.status}`}catch{e=`HTTP error ${r.status}`}throw console.error(`fetchWithRetry error: ${e}`),Error(e)}}catch(e){if(clearTimeout(c),o=e instanceof Error?e:Error(String(e)),n===i-1){let e=`Failed after ${i} retries. Last error: ${o.message}`;throw console.error(`fetchWithRetry error: ${e}`),Error(e)}let t=a+n**2*50;await new Promise(e=>setTimeout(e,t))}}throw Error(`Failed after ${i} retries`)}export{e as t};
//# sourceMappingURL=fetch-with-retry-CTDDLz3Q.mjs.map