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 • 870 B
JavaScript
import{ResponseError as e}from"../error.mjs";import{sseTextDecoderPlugin as t}from"../sse.mjs";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&&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({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}}}export{a as dedupePlugin,i as isDedupeError,t as sseTextDecoderPlugin};
//# sourceMappingURL=index.mjs.map