mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-20 09:01:19 +00:00
fix(client): allow req middlewares to run on empty init
This commit is contained in:
@@ -24,10 +24,11 @@ export class ApiClient {
|
||||
this.middlewares = middlewares
|
||||
}
|
||||
|
||||
async request<T>(...[url, init]: Parameters<typeof fetch>): Promise<[Response, T]> {
|
||||
const finalInit = init
|
||||
? this.middlewares.reduce((prevInit, middleware) => middleware(url, prevInit), init)
|
||||
: undefined
|
||||
async request<T>(...[url, init = {}]: Parameters<typeof fetch>): Promise<[Response, T]> {
|
||||
const finalInit = this.middlewares.reduce(
|
||||
(prevInit, middleware) => middleware(url, prevInit),
|
||||
init,
|
||||
)
|
||||
return fetch(url instanceof Request ? url : new URL(url, this.baseUrl), finalInit).then((res) =>
|
||||
Promise.all([Promise.resolve(res), res.json()]),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user