question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fetch doesn’t handle try/catch when http2 request fails

See original GitHub issue

any ideas how to fix this in pooledMap? I wrapped my entire fetch request with Try catch and it still crashes

TypeError: error sending request for url (https://briskreader.com/api/1/fetch?url=https://www.scmp.com/news/hong-kong/law-and-crime/article/3157622/hong-kong-emergency-services-search-hiker-missing?utm_source=rss_feed): http2 error: connection error received: not a result of an error
    at async mainFetch (deno:ext/fetch/26_fetch.js:266:14)
error: Uncaught (in promise) AggregateError: Threw while mapping.
        new AggregateError(errors, "Threw while mapping."),
        ^
    at https://deno.land/std@0.115.1/async/pool.ts:63:9

this happens if my api goes down while I’m trying to send a request to it…if nginx doesnj’t server a 200 then my script crashes

i’m using systemd and if i crash the api it restarts, but during that time my pooledMap crashes from my script.

i basically did try { ... fetch() } catch(err) { return Promise.resolve() }

doesnt’ seem to work with pooledMap

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ralyodiocommented, Dec 6, 2021

So I guess my fetch pattern sucked and doesn’t do what I thought it did.

I replaced:

cons res = await fetch(url).catch((err) => {
     console.error(err);
     return Promise.resolve()
});

with a real try/catch:

try {
  cons res = await fetch(url);
  if (res.ok) {
    body = await res.text();
 }
} catch(err) {
   console.error(err);
return Promise.resolve();
}

and now it doesn’t crash.

0reactions
ralyodiocommented, Dec 6, 2021

I also get this error sometimes:

TypeError: Fetch failed: Maximum number of redirects (20) reached

TypeError: Fetch failed: Maximum number of redirects (20) reached
    at deno:ext/fetch/26_fetch.js:440:27
error: Uncaught (in promise) AggregateError: Threw while mapping.
        new AggregateError(errors, "Threw while mapping."),
        ^
    at https://deno.land/std@0.116.0/async/pool.ts:63:9

try/catch is ignored

Read more comments on GitHub >

github_iconTop Results From Across the Web

Try-Catch not handling errors with an https.get request in Node
The reason why try...catch.. fails is that it is meant for handling synchronous errors. https.get() is asynchronous and cannot be handled ...
Read more >
Handling Failed HTTP Responses With fetch() - TJ VanToll
Per MDN, the fetch() API only rejects a promise when a “network error is encountered, although this usually means permissions issues or similar....
Read more >
Fetch - Error Handling for Failed HTTP Responses and ...
A quick example of how to handle both network errors and HTTP errors (4xx or 5xx) for fetch requests in a single catch...
Read more >
Errors | Node.js v19.3.0 Documentation
js supports several mechanisms for propagating and handling errors that occur while an application is running. How these errors are reported and handled...
Read more >
Error in curl::curl_fetch_memory(url, handle = handle ... - GitHub
Everything seems to work fine, but occasionally I get the error message "Auto-refreshing stale OAuth token." followed by the more cryptic error ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found