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