Last active
October 24, 2017 21:29
-
-
Save cyberwombat/f2b8e15618f732ee543e95efe34a28bd to your computer and use it in GitHub Desktop.
4xx handling with various HTTP client libs for node
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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