-
-
Save jkantr/7a35d03008e25829dadaeb28e786772a to your computer and use it in GitHub Desktop.
This file contains 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
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