From c284df1784865429adb5dcf88ab240dea384fc28 Mon Sep 17 00:00:00 2001 From: elineda Date: Thu, 1 Feb 2024 11:26:51 +0100 Subject: [PATCH 1/4] Improve handling when DJDT views don't respond with JSON [m] add a catch for catch json error and display it with a better message --- debug_toolbar/static/debug_toolbar/js/utils.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/debug_toolbar/static/debug_toolbar/js/utils.js b/debug_toolbar/static/debug_toolbar/js/utils.js index b4c7a4cb8..73f9d17ca 100644 --- a/debug_toolbar/static/debug_toolbar/js/utils.js +++ b/debug_toolbar/static/debug_toolbar/js/utils.js @@ -75,7 +75,11 @@ function ajax(url, init) { return fetch(url, init) .then(function (response) { if (response.ok) { - return response.json(); + return response.json().catch(function(error){ + return Promise.reject( + new Error("The toolbar request response is a invalid Json object : " + error) + ); + }) } return Promise.reject( new Error(response.status + ": " + response.statusText) From eb53b01158ac4406abbada1efbdd5260d388be64 Mon Sep 17 00:00:00 2001 From: elineda Date: Tue, 6 Feb 2024 10:18:26 +0100 Subject: [PATCH 2/4] Improve handling when DJDT views don't respond with JSON [m] Put a better response [+] Add changelog --- debug_toolbar/static/debug_toolbar/js/utils.js | 2 +- docs/changes.rst | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/debug_toolbar/static/debug_toolbar/js/utils.js b/debug_toolbar/static/debug_toolbar/js/utils.js index 73f9d17ca..59de215a5 100644 --- a/debug_toolbar/static/debug_toolbar/js/utils.js +++ b/debug_toolbar/static/debug_toolbar/js/utils.js @@ -77,7 +77,7 @@ function ajax(url, init) { if (response.ok) { return response.json().catch(function(error){ return Promise.reject( - new Error("The toolbar request response is a invalid Json object : " + error) + new Error("The response is a invalid Json object : " + error) ); }) } diff --git a/docs/changes.rst b/docs/changes.rst index e2a610991..eb9e0a2c2 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -4,6 +4,8 @@ Change log Pending ------- +* Display a better error message when request toolbar are not a valid json + 4.3.0 (2024-02-01) ------------------ From 016d794d3b3f233ef15952fce43c5a6300ea1790 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 6 Feb 2024 09:23:00 +0000 Subject: [PATCH 3/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- debug_toolbar/static/debug_toolbar/js/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debug_toolbar/static/debug_toolbar/js/utils.js b/debug_toolbar/static/debug_toolbar/js/utils.js index 59de215a5..c37525f13 100644 --- a/debug_toolbar/static/debug_toolbar/js/utils.js +++ b/debug_toolbar/static/debug_toolbar/js/utils.js @@ -79,7 +79,7 @@ function ajax(url, init) { return Promise.reject( new Error("The response is a invalid Json object : " + error) ); - }) + }); } return Promise.reject( new Error(response.status + ": " + response.statusText) From fc87adbe6a270610d89d0267f3e0cac1a92ef409 Mon Sep 17 00:00:00 2001 From: Tim Schilling Date: Thu, 22 Feb 2024 13:44:59 -0600 Subject: [PATCH 4/4] Update docs/changes.rst --- docs/changes.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/changes.rst b/docs/changes.rst index eb9e0a2c2..5d2122aaf 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -4,7 +4,8 @@ Change log Pending ------- -* Display a better error message when request toolbar are not a valid json +* Display a better error message when the toolbar's requests + return invalid json. 4.3.0 (2024-02-01) ------------------