Skip to content

Instantly share code, notes, and snippets.

@justsml
Last active December 23, 2018 07:05
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 justsml/81919a72897ebc503c6b34a556a9bde2 to your computer and use it in GitHub Desktop.
Save justsml/81919a72897ebc503c6b34a556a9bde2 to your computer and use it in GitHub Desktop.
const isOk = response => response.ok ? response.json() : Promise.reject(new Error('Failed to load data from server'))
fetch('https://api.github.com/orgs/nodejs')
.then(isOk) // <= Use `isOk` function here
.then(data => {
console.log(data) // Prints result from `response.json()`
})
.catch(error => console.error(error))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment