Last active
August 31, 2017 19:33
-
-
Save doug2k1/b7d19d8ac2184d34fbdbb44155c62ccb to your computer and use it in GitHub Desktop.
Handling HTTP failed request in JavaScript - https://medium.com/douglas-matoso-english/http-primer-for-frontend-developers-f091a2070637
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
// the request: | |
// try to GET an nonexistent URI | |
fetch('https://api.github.com/nonexistent-uri') | |
.then(response => { | |
if (response.ok) { | |
// we should not reach here | |
console.log('success') | |
} else { | |
console.log(response.status) | |
} | |
}) | |
// will log: | |
// 404 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment