Last active
September 1, 2017 02:54
-
-
Save doug2k1/bc1611f23d3fbd0683ec76903ef3a535 to your computer and use it in GitHub Desktop.
Tratando falha em requisição HTTP com JavaScript - https://medium.com/douglas-matoso-brasil/b%C3%A1sico-de-http-para-desenvolvedores-frontend-954fa3688c87
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
// requisição: | |
// tenta fazer um GET em URI inexistente | |
fetch('https://api.github.com/nonexistent-uri') | |
.then(response => { | |
if (response.ok) { | |
// não deve entrar aqui | |
console.log('success') | |
} else { | |
console.log(response.status) | |
} | |
}) | |
// vai logar: | |
// 404 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment