any possible way to include timeout on fetch()?
See original GitHub issuecouldn’t find the docs for this repository… my code looks like this:
fetch('/test', { method: 'POST', body: data })
.then(function(response) {
if (response.status >= 400) {
throw new Error("Bad response from server");
}
return response.json();
})
.then(function(response) {
console.log(response)
});
would like to fake a server response for the fetch… any ideas?
thanks in advance
Issue Analytics
- State:
- Created 8 years ago
- Reactions:22
- Comments:18
Top Results From Across the Web
Fetch API request timeout? - javascript - Stack Overflow
there's no timeout support in the fetch API yet. But it could be achieved by wrapping it in a promise.
Read more >How to Set Timeout with the JavaScript Fetch API using ...
Use the setTimeout function to trigger the abort method after a specified time(convert to seconds by multiplying by 1000) and returns the ...
Read more >Quickie fetch timeout | Ben Ilegbodu
I've always used the native Fetch API because it usually gives me everything I need without having to include another dependency. However, the ......
Read more >How to timeout fetch requests in JavaScript - CodingDeft.Com
Adding timeout feature ... Now let's add the timeout feature to the loadData function. ... Here we are passing the timeout value as...
Read more >JavaScript fetch with Timeout
const FETCH_TIMEOUT = 5000; let didTimeOut = false; new Promise(function(resolve, reject) { const timeout = setTimeout(function() { didTimeOut = ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Create a timeoutPromise wrapper…
You can then wrap any promise…
It won’t actually cancel an underlying connection, but will allow you to timeout a promise.
This is how you should be handling abort: