async function f(l,c,w={}){let{timeout:m=5e3,maxRetries:s=10,retryDelay:n=1e3}=w,a=null;for(let o=0;o<s;o++){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(o,2)*50;await new Promise(t=>setTimeout(t,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 console.error(e),new Error(e)}}catch(r){if(clearTimeout(u),a=r instanceof Error?r:new Error(String(r)),o===s-1){let t=`Failed after ${s} retries. Last error: ${a.message}`;throw console.error(t),new Error(t)}let e=n+Math.pow(o,2)*50;await new Promise(t=>setTimeout(t,e))}}throw new Error(`Failed after ${s} retries`)}export{f as a};
