Skip to content

Instantly share code, notes, and snippets.

@jkantr
Created May 26, 2017 15:10
Show Gist options
  • Save jkantr/7a35d03008e25829dadaeb28e786772a to your computer and use it in GitHub Desktop.
Save jkantr/7a35d03008e25829dadaeb28e786772a to your computer and use it in GitHub Desktop.
const fetch = require('node-fetch')
function checkStatus(response) {
if (response.status >= 200 && response.status < 300) {
return response
} else {
var error = new Error(response.statusText)
error.response = response
throw error
}
}
fetch(url)
.then(checkStatus)
.then(res => res.json())
.then((data) => {
console.log('request succeeded with JSON response', data)
}).catch((error) => {
console.log('request failed', error)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment