hook-fetch
Version:
A lightweight and modern HTTP request library developed based on the native Fetch API of the browser, providing a user-friendly interface similar to Axios and powerful extensibility.
2 lines • 887 B
JavaScript
const e=require(`../error.cjs`),t=require(`../sse.cjs`);function n(e,t,n,r){return`${e}::${t}::${JSON.stringify(n)}::${JSON.stringify(r)}`}const r=`DedupeError`;function i(t){return t instanceof e.ResponseError&&t.name===r}function a(t={}){let i=new Map;return{name:`dedupe`,async beforeRequest(t){if(t.extra?.dedupeAble??!0){let a=n(t.url,t.method,t.params,t.data),o=i.get(a);if(o)throw new e.ResponseError({message:`Dedupe error`,status:400,statusText:`Dedupe error`,config:t,name:r});i.set(a,!0)}return t},afterResponse:e=>{let t=n(e.config.url,e.config.method,e.config.params,e.config.data);return i.has(t)&&i.delete(t),e},onError:e=>{if(e.config){let t=n(e.config.url,e.config.method,e.config.params,e.config.data);i.has(t)&&i.delete(t)}return e}}}exports.dedupePlugin=a,exports.isDedupeError=i,exports.sseTextDecoderPlugin=t.sseTextDecoderPlugin;
//# sourceMappingURL=index.cjs.map