v0.14.23-fixed_js
This commit is contained in:
@@ -413,8 +413,12 @@ async function api(path, options = {}) {
|
||||
}
|
||||
const response = await fetch(withBase(path), { ...options, headers, body });
|
||||
if (response.status === 401) {
|
||||
showTokenDialog();
|
||||
throw new Error(tr('auth.invalid'));
|
||||
const invalidToken = Boolean(app.token);
|
||||
const message = invalidToken ? tr('auth.invalid') : tr('auth.required');
|
||||
showTokenDialog(invalidToken ? message : '');
|
||||
const error = new Error(message);
|
||||
error.status = response.status;
|
||||
throw error;
|
||||
}
|
||||
if (!response.ok) {
|
||||
let message = tr('error.http', { status: response.status });
|
||||
|
||||
@@ -315,8 +315,13 @@ document.addEventListener('cancel', event => {
|
||||
if (confirmDiscardForm(form)) dialog.close();
|
||||
}, true);
|
||||
|
||||
function showTokenDialog() {
|
||||
function showTokenDialog(errorMessage = '') {
|
||||
const dialog = $('#tokenDialog');
|
||||
const form = $('#tokenForm');
|
||||
if (form) {
|
||||
clearFormErrors(form);
|
||||
if (errorMessage) showFieldError(form.elements.token, errorMessage);
|
||||
}
|
||||
if (!dialog.open) dialog.showModal();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user