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 <oleonard@myacpl.org>
Signed-off-by: Matt Blenkinsop <matt.blenkinsop@openfifth.co.uk>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 14635a2db4)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Jonathan Druart 2025-06-16 11:10:32 +02:00 committed by Paul Derscheid
parent fc419ce2ef
commit 0df46127d7
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
1 changed files with 5 additions and 3 deletions

View File

@ -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 => {