OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Don't report a fetch timeout as an uncaught exception

  • Thread starter Thread starter Basj
  • Start date Start date
B

Basj

Guest
I use:

Code:
fetch("/test", { signal: AbortSignal.timeout(2000) })
    .then(r => r.json())
    .then(r => { console.log(r["data"]) });

with the method from Fetch API request timeout? to abort the request after 2 seconds if no response.

In the case of a timeout, I have a JS error in the console:

Uncaught (in promise) DOMException: The operation timed out.

What's the simplest way to avoid having this reported as an error?

I would like the timeouts to be silently ignored.

Is this possible with fetch("/test", { signal: AbortSignal.timeout(2000) })? I specifically wanted to use this solution instead of more complex solutions of Fetch API request timeout?.

<p>I use:</p>
<pre><code>fetch("/test", { signal: AbortSignal.timeout(2000) })
.then(r => r.json())
.then(r => { console.log(r["data"]) });
</code></pre>
<p>with the method from <a href="https://stackoverflow.com/questions/46946380/fetch-api-request-timeout">Fetch API request timeout?</a> to abort the request after 2 seconds if no response.</p>
<p>In the case of a timeout, I have a JS error in the console:</p>
<blockquote>
<p>Uncaught (in promise) DOMException: The operation timed out.</p>
</blockquote>
<p>What's the simplest way to avoid having this reported as an error?</p>
<p>I would like the timeouts to be silently ignored.</p>
<p>Is this possible with <code>fetch("/test", { signal: AbortSignal.timeout(2000) })</code>? I specifically wanted to use this solution instead of more complex solutions of <a href="https://stackoverflow.com/questions/46946380/fetch-api-request-timeout">Fetch API request timeout?</a>.</p>
 
Top