Skip to content

Commit

Permalink
test: port node-fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Aug 5, 2021
1 parent f1e485c commit 6749e38
Show file tree
Hide file tree
Showing 19 changed files with 4,222 additions and 444 deletions.
20 changes: 19 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,25 @@ function makeDispatcher (fn) {
module.exports.setGlobalDispatcher = setGlobalDispatcher
module.exports.getGlobalDispatcher = getGlobalDispatcher

module.exports.fetch = makeDispatcher(api.fetch)
if (api.fetch) {
const _fetch = makeDispatcher(api.fetch)
module.exports.fetch = async function fetch (...args) {
try {
return await _fetch(...args)
} catch (err) {
// TODO (fix): This is a little weird. Spec compliant?
if (err.code === 'ERR_INVALID_URL') {
const er = new TypeError('Invalid URL')
er.cause = err
throw er
}
throw err
}
}
module.exports.Headers = api.fetch.Headers
module.exports.Response = api.fetch.Response
}

module.exports.request = makeDispatcher(api.request)
module.exports.stream = makeDispatcher(api.stream)
module.exports.pipeline = makeDispatcher(api.pipeline)
Expand Down
Loading

0 comments on commit 6749e38

Please sign in to comment.