Skip to content

Instantly share code, notes, and snippets.

@diego3g
Created December 18, 2017 15:22
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 diego3g/e045b3994aab1eb41af6447796b1b141 to your computer and use it in GitHub Desktop.
Save diego3g/e045b3994aab1eb41af6447796b1b141 to your computer and use it in GitHub Desktop.
// Sintaxe antiga (ES6)
function fetchUser() {
api.get('/users/diego3g')
.then(response => console.log(response));
.catch(err => console.log('Erro:', err));
}
// Nova sintaxe (ES8)
async function fetchUser() {
try {
const response = await api.get('/users/diego3g');
console.log(response);
} catch (err) {
console.log('Erro:', err);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment