zkat / make-fetch-happen

Get in loser, we're making requests!
Other
384 stars 27 forks source link

Error when first argument is a Request instance #56

Open xzyfer opened 6 years ago

xzyfer commented 6 years ago

The documentation states

fetch(uriOrRequest, [opts]) -> Promise

However using a Request instance results in an error.

➜ node
> const fetch = require('make-fetch-happen');
undefined
> const Request = require('node-fetch').Request;
undefined
> fetch(new Request('https://google.com')).then(console.log)
TypeError: Parameter "url" must be a string, not object
    at Url.parse (url.js:102:11)
    at Object.urlParse [as parse] (url.js:96:13)
    at getProxyUri (/Users/michaelmifsud/src/shop/app/node_modules/make-fetch-happen/agent.js:116:24)
    at getAgent (/Users/michaelmifsud/src/shop/app/node_modules/make-fetch-happen/agent.js:14:17)
    at remoteFetch (/Users/michaelmifsud/src/shop/app/node_modules/make-fetch-happen/index.js:310:17)
    at cachingFetch (/Users/michaelmifsud/src/shop/app/node_modules/make-fetch-happen/index.js:176:10)
    at repl:1:1
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at REPLServer.defaultEval (repl.js:239:29)
    at bound (domain.js:301:14)

From a glance at the code the first parameter to fetch is generally assumed to be a string.