refactor: replace repeated GET+JSON parsing with reusable getJson helper

This commit is contained in:
2025-09-19 13:58:07 +02:00
parent 9c730e8f42
commit 877c88d52b
2 changed files with 11 additions and 5 deletions

View File

@@ -33,6 +33,14 @@ function getRequest(url) {
return sendRequest('GET', url);
}
function getJson(url) {
return sendRequest('GET', url).then(res => {
if (res.ok)
return res.json();
throw new Error(`Request failed with status ${res.status}`);
});
}
function postRequest(url, body = undefined) {
return sendRequest('POST', url, body);
}
@@ -48,8 +56,7 @@ function signEnvelope(annotations) {
}
async function getAnnotationParams(leftInInch = 0, topInInch = 0, inchToPointFactor = 72) {
const annotParams = await getRequest("/api/Config/Annotations")
.then(res => res.json());
const annotParams = await getJson("/api/Config/Annotations");
for (var key in annotParams) {
var annot = annotParams[key];
@@ -77,8 +84,7 @@ function redirRejected() {
}
async function setLanguage(language) {
const hasLang = await getRequest('/api/localization/lang')
.then(res => res.json())
const hasLang = await getJson('/api/localization/lang')
.then(langs => langs.includes(language));
if (hasLang)