fetch-plus icon indicating copy to clipboard operation
fetch-plus copied to clipboard

options.fetch function is called with no arguments

Open bman654 opened this issue 7 years ago • 2 comments

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")

bman654 avatar Jul 12 '17 04:07 bman654

Return myFetch in an anonymous function. It has to do with how fetch expects function-wrapped values.

RickWong avatar Jul 12 '17 08:07 RickWong

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

bman654 avatar Jul 12 '17 10:07 bman654