access: Fix error handling in JS
This commit is contained in:
@ -129,7 +129,7 @@ function render() {
|
|||||||
main.className = 'overview';
|
main.className = 'overview';
|
||||||
main.innerHTML = `
|
main.innerHTML = `
|
||||||
<h1>${CLIENTS[client].name}</h1>`;
|
<h1>${CLIENTS[client].name}</h1>`;
|
||||||
updateOverview(client).then();
|
update();
|
||||||
} else {
|
} else {
|
||||||
window.location.hash = `#/${client}`;
|
window.location.hash = `#/${client}`;
|
||||||
}
|
}
|
||||||
@ -142,7 +142,17 @@ function update() {
|
|||||||
// do nothing
|
// do nothing
|
||||||
} else {
|
} else {
|
||||||
if (hash === `#/${client}`) {
|
if (hash === `#/${client}`) {
|
||||||
updateOverview(client).then();
|
updateOverview(client)
|
||||||
|
.then()
|
||||||
|
.catch(e => {
|
||||||
|
if (e instanceof ApiError && e.statusCode === 401) {
|
||||||
|
window.localStorage.removeItem(`${CLIENT}/${client}/token`);
|
||||||
|
window.localStorage.removeItem(`${CLIENT}/${client}/password`);
|
||||||
|
window.location.hash = `#/${client}/login`;
|
||||||
|
} else {
|
||||||
|
alert(e.localizedMessage ?? ERROR_MESSAGES[e.message] ?? `Unbekannter Fehler: ${e.message}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,7 +182,7 @@ function actionLogin(form) {
|
|||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
const error = document.createElement('div');
|
const error = document.createElement('div');
|
||||||
error.className = 'error';
|
error.className = 'error';
|
||||||
error.innerText = e.localizedMessage ?? ERROR_MESSAGES[e.message] ?? 'Unbekannter Fehler';
|
error.innerText = e.localizedMessage ?? ERROR_MESSAGES[e.message] ?? `Unbekannter Fehler\n(${e.message})`;
|
||||||
form.insertBefore(error, form.lastChild.previousSibling);
|
form.insertBefore(error, form.lastChild.previousSibling);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ const ERROR_MESSAGES = {
|
|||||||
class ApiError extends Error {
|
class ApiError extends Error {
|
||||||
constructor(statusCode, message) {
|
constructor(statusCode, message) {
|
||||||
super(statusCode + ' - ' + message);
|
super(statusCode + ' - ' + message);
|
||||||
|
this.statusCode = statusCode;
|
||||||
this.name = 'ApiError';
|
this.name = 'ApiError';
|
||||||
this.localizedMessage = ERROR_MESSAGES[statusCode];
|
this.localizedMessage = ERROR_MESSAGES[statusCode];
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user