refactor: replace repeated GET+JSON parsing with reusable getJson helper
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user