From 4a5f8d89e21b1f25ace302919d154c55506e4e07 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. --- 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 8f2c3d3ab27..ee2722faa64 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 => { -- 2.34.1