UNPKG

wretch

Version:

A tiny wrapper built around fetch with an intuitive syntax.

3 lines (2 loc) 1.06 kB
var global,factory;global=this,factory=function(e){const t=(e,t)=>e*t,o=e=>e&&e.ok;e.retry=({delayTimer:e=500,delayRamp:r=t,maxAttempts:n=10,until:l=o,onRetry:s=null,retryOnNetworkError:i=0,resolveWithLatestResponse:a=0}={})=>t=>(o,f)=>{let c=0;const u=(d,y)=>Promise.resolve(l(d,y)).then((l=>l?d&&a?d:y?Promise.reject(y):d:(c++,!n||c<=n?new Promise((n=>{const l=r(e,c);setTimeout((()=>{"function"==typeof s?Promise.resolve(s({response:d,error:y,url:o,options:f})).then(((e={})=>{var r,l;n(t(null!==(r=e&&e.url)&&void 0!==r?r:o,null!==(l=e&&e.options)&&void 0!==l?l:f))})):n(t(o,f))}),l)})).then(u).catch((e=>{if(!i)throw e;return u(null,e)})):d&&a?d:Promise.reject(y||new Error("Number of attempts exceeded.")))));return t(o,f).then(u).catch((e=>{if(!i)throw e;return u(null,e)}))}},"object"==typeof exports&&"undefined"!=typeof module?factory(exports):"function"==typeof define&&define.amd?define(["exports"],factory):factory((global="undefined"!=typeof globalThis?globalThis:global||self).wretchRetryMiddleware={}); //# sourceMappingURL=retry.min.js.map