xior
Version:
A lite http request lib based on fetch with plugins support and similar API to axios.
2 lines (1 loc) • 881 B
JavaScript
import{b as p,i as s,n as b,w as c}from"../chunk-JGM66FSA.mjs";import{a as X,d as R}from"../chunk-BOVQDIMN.mjs";function x(I={}){let{retryTimes:h,retryInterval:q,enableRetry:C,onRetry:g}=X({retryTimes:2,retryInterval:3e3},I);return function(T,o){return r=>R(this,null,function*(){let{retryTimes:v=h,retryInterval:a=q,enableRetry:l=C,onRetry:d=g}=r,u=0;function m(w=!1){return R(this,null,function*(){var E;if(w&&(o!=null&&o.REQI))for(let e of o.REQI)r=yield e(r);try{let e=T(r),i=0,t=[];for((E=o==null?void 0:o.RESI)==null||E.forEach(function(n){t.push(n.fn,n.onRejected)});t.length>i;)e=e.then(t[i++],t[i++]);return r._did=!0,yield e}catch(e){let i=r.method===b||!!r.isGet,t=typeof l,y=t===p,n=s;if(y&&(n=l(r,e)),n===s&&(n=y||t===`${s}`?i:!!l),u>=v||!n)throw e;u++;let f=typeof a===p?a(u,r,e):a;return f&&f>0&&(yield c(f)),d&&d(r,e,u),m(!0)}})}return m()})}}export{x as default};