From 0b4cf3c7bb994adfee54391a3027658d42727216 Mon Sep 17 00:00:00 2001 From: Guybrush aka Gabriele Labita Date: Fri, 2 Jan 2026 21:16:50 +0100 Subject: [PATCH] fix: check for server unreachable error. Signed-off-by: Guybrush aka Gabriele Labita --- scripts/js/login.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/scripts/js/login.js b/scripts/js/login.js index 46ec2dd4..a0b98220 100644 --- a/scripts/js/login.js +++ b/scripts/js/login.js @@ -25,31 +25,34 @@ function redirect() { globalThis.location.replace(target); } +function showErrorMessage(errorMessage) { + $("#error-message").text(errorMessage); + $("#error-label").show(); +} + function wrongPassword(isError = false, isSuccess = false, data = null) { if (isError) { let isErrorResponse = false; let isInvalidTOTP = false; - + let errorMessage = "Wrong password!"; // Reset hint and error message $("#error-message").text(""); $("#error-hint").hide(); $("#error-hint").text(""); - if (data !== null && "error" in data.responseJSON && "message" in data.responseJSON.error) { + + if ("error" in data.responseJSON && "message" in data.responseJSON.error) { // This is an error, highlight both the password and the TOTP field isErrorResponse = true; // Check if the error is caused by an invalid TOTP token isInvalidTOTP = data.responseJSON.error.message === "Invalid 2FA token"; - $("#error-message").text(data.responseJSON.error.message); + errorMessage = data.responseJSON.error.message; if ("hint" in data.responseJSON.error && data.responseJSON.error.hint !== null) { $("#error-hint").text(data.responseJSON.error.hint); $("#error-hint").show(); } - } else { - $("#error-message").text("Wrong password!"); } - $("#error-label").show(); - + showErrorMessage(errorMessage); // Always highlight the TOTP field on error if (isErrorResponse) $("#totp_input").addClass("has-error"); @@ -105,7 +108,12 @@ function doLogin(password) { redirect(); }) .fail(data => { - wrongPassword(true, false, data); + if (!data || !data.responseJSON) { + showErrorMessage("Server unreachable!"); + } else { + wrongPassword(true, false, data); + } + NProgress.done(); utils.enableAll(); });