Skip to content

Instantly share code, notes, and snippets.

@allangrds
Created October 26, 2020 20:52
Show Gist options
  • Save allangrds/a251bec08aa24e5656f13aa641b727c3 to your computer and use it in GitHub Desktop.
Save allangrds/a251bec08aa24e5656f13aa641b727c3 to your computer and use it in GitHub Desktop.
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