Skip to content

Instantly share code, notes, and snippets.

@cyberwombat
Last active October 24, 2017 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyberwombat/f2b8e15618f732ee543e95efe34a28bd to your computer and use it in GitHub Desktop.
Save cyberwombat/f2b8e15618f732ee543e95efe34a28bd to your computer and use it in GitHub Desktop.
4xx handling with various HTTP client libs for node
// request-promise-native
const body = request({ url: url, json: true })
const res = await t.throws(body);
console.log(res.error)
// node-fetch
const body = await fetch(url)
console.log(await body.json())
// axios
const body = axios.get(url)
const res = await t.throws(body);
console.log(res.response.data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment