diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js index 329bce669..077bc930a 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js @@ -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: { diff --git a/docs/changes.rst b/docs/changes.rst index 608843e0f..f11d4889e 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -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) ------------------