From 0df46127d7ff1ecae4b72ddad8efb38be24ca9c0 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 16 Jun 2025 11:10:32 +0200 Subject: [PATCH] Bug 40173: Return the response early if the caller needs it We returned the response too late: if something was wrong we processed the response already and thrown an error. This may introduce side-effects but it feels like a correct change. Signed-off-by: Owen Leonard Signed-off-by: Matt Blenkinsop Signed-off-by: Martin Renvoize Signed-off-by: Lucas Gass (cherry picked from commit 14635a2db4c57399135734fa84ba0fa836f4ba53) Signed-off-by: Paul Derscheid --- koha-tmpl/intranet-tmpl/prog/js/fetch/http-client.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/fetch/http-client.js b/koha-tmpl/intranet-tmpl/prog/js/fetch/http-client.js index 8f2c3d3ab2..ee2722faa6 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/fetch/http-client.js +++ b/koha-tmpl/intranet-tmpl/prog/js/fetch/http-client.js @@ -68,6 +68,11 @@ class HttpClient { const is_json = response.headers .get("content-type") ?.includes("application/json"); + + if (return_response || !is_json) { + return response; + } + if (!response.ok) { return response.text().then(text => { let message; @@ -83,9 +88,6 @@ class HttpClient { throw new Error(message); }); } - if (return_response || !is_json) { - return response; - } return response.json(); }) .then(result => {