Skip to content

Fix for exception-unhandled "forked" Promise chain #2101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions debug_toolbar/static/debug_toolbar/js/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,25 @@ const djdt = {

const origFetch = window.fetch;
window.fetch = function (...args) {
// Heads up! Before modifying this code, please be aware of the
// possible unhandled errors that might arise from changing this.
// For details, see
// https://github.com/django-commons/django-debug-toolbar/pull/2100
const promise = origFetch.apply(this, args);
promise.then((response) => {
return promise.then((response) => {
if (response.headers.get("djdt-store-id") !== null) {
handleAjaxResponse(response.headers.get("djdt-store-id"));
try {
handleAjaxResponse(
response.headers.get("djdt-store-id")
);
} catch (err) {
throw new Error(
`"${err.name}" occurred within django-debug-toolbar: ${err.message}`
);
}
}
// Don't resolve the response via .json(). Instead
// continue to return it to allow the caller to consume as needed.
return response;
});
return promise;
};
},
cookie: {
Expand Down
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Pending
* Added a Makefile target (``make help``) to get a quick overview
of each target.
* Avoided reinitializing the staticfiles storage during instrumentation.
* Fix for exception-unhandled "forked" Promise chain in rebound window.fetch

5.0.1 (2025-01-13)
------------------
Expand Down