UNPKG

@artmate/chat

Version:

借鉴字节开源react库AntX,通过vue实现的版本

29 lines (28 loc) 754 B
const c = async (i, r = {}) => { const { fetch: n = globalThis.fetch, middlewares: t = {}, ...f } = r; if (typeof n != "function") throw new TypeError("The options.fetch must be a typeof fetch function!"); let o = [i, f]; typeof t.onRequest == "function" && (o = await t.onRequest(...o)); let e = await n(...o); if (typeof t.onResponse == "function") { const s = await t.onResponse(e); if (!(s instanceof Response)) throw new TypeError( "The options.onResponse must return a Response instance!" ); e = s; } if (!e.ok) throw new Error(`Fetch failed with status ${e.status}`); if (!e.body) throw new Error("The response body is empty."); return e; }; export { c as default };