Last active
August 28, 2024 23:48
-
-
Save justsml/81919a72897ebc503c6b34a556a9bde2 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 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