Skip to content

Commit 13c2f96

Browse files
committed
Fix for uncatchable AbortErrors
Patching `window.fetch` without handling the `AbortError` results in JS code that uses fetch, becoming unable to catch these errors. As such, application errors will be emitted to the console (and in the case of webpack-dev-server, to the browser window), that are very mysterious. Even if one has try/catch blocks within an async function, or then/catch blocks for the Promise using `fetch()`, these errors will not be catched. I am not fully in the know as to why it works this way (the internals of an async/Promise are very convoluted especially when `this` is involved as in here), but I suspect the patched call will emit its own `AbortError` extra to the one that comes from the original one, and the uncatched one in the patched function will resurface even after catching one of them.
1 parent e885fe9 commit 13c2f96

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

debug_toolbar/static/debug_toolbar/js/toolbar.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,9 @@ const djdt = {
329329
// Don't resolve the response via .json(). Instead
330330
// continue to return it to allow the caller to consume as needed.
331331
return response;
332+
}).catch((err) => {
333+
if (err.name === 'AbortError') return
334+
throw(e);
332335
});
333336
return promise;
334337
};

0 commit comments

Comments
 (0)