wretch
Version:
A tiny wrapper built around fetch with an intuitive syntax.
3 lines (2 loc) • 778 B
JavaScript
const e=(e,r)=>e*r,r=e=>e&&e.ok;exports.retry=({delayTimer:t=500,delayRamp:o=e,maxAttempts:n=10,until:s=r,onRetry:l=null,retryOnNetworkError:i=0,resolveWithLatestResponse:u=0}={})=>e=>(r,m)=>{let c=0;const a=(h,p)=>Promise.resolve(s(h,p)).then((s=>s?h&&u?h:p?Promise.reject(p):h:(c++,!n||c<=n?new Promise((n=>{const s=o(t,c);setTimeout((()=>{"function"==typeof l?Promise.resolve(l({response:h,error:p,url:r,options:m})).then(((t={})=>{var o,s;n(e(null!==(o=t&&t.url)&&void 0!==o?o:r,null!==(s=t&&t.options)&&void 0!==s?s:m))})):n(e(r,m))}),s)})).then(a).catch((e=>{if(!i)throw e;return a(null,e)})):h&&u?h:Promise.reject(p||new Error("Number of attempts exceeded.")))));return e(r,m).then(a).catch((e=>{if(!i)throw e;return a(null,e)}))};
//# sourceMappingURL=retry.min.cjs.map