Created
October 26, 2020 20:52
-
-
Save allangrds/a251bec08aa24e5656f13aa641b727c3 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 controller = new AbortController(); | |
const options = { | |
method: 'POST', | |
signal: controller.signal, | |
body: JSON.stringify({ | |
firstName: 'David', | |
lastName: 'Pollock' | |
}) | |
}; | |
const promise = fetch('/login', options); | |
const timeoutId = setTimeout(() => controller.abort(), 4000); | |
promise | |
.then(response => {/* tratamento da resposta */}) | |
.catch(error => console.error('timeout excedido')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment