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