fetch-plus
fetch-plus copied to clipboard
options.fetch function is called with no arguments
If you supply a fetch function via the options argument, it gets called with no arguments when fetchPlus calls computeObject(options)
.
Example:
function myFetch(...args) {
if (args.length === 0) { console.log(" :( "); }
return fetch(...args);
}
const client = createClient("http://localhost", { fetch: myFetch });
client.get("/foo"); // calls myFetch(), then calls myFetch("http://localhost/foo")
Return myFetch in an anonymous function. It has to do with how fetch expects function-wrapped values.
That doesn't work. It rejects the promise with the fetch function as the rejection value:
function myFetch(...args) {
if (args.length === 0) { console.log(" :( "); }
return fetch(...args);
}
const client = createClient("http://localhost", { fetch: () => myFetch });
client.get("/foo").catch(err => console.log(err === myFetch)); // prints true