fix: display friendly error message for password validation on signup

The signup function was not reading the response body before throwing
an error, causing users to see only "400 Bad Request" instead of the
actual validation message.

Changes:
- Read response body in signup() to capture error details
- Add 400 status handling in Login.vue to display errors in form
- Parse password length errors to show user-friendly message
- Add translation string for password minimum length error

Fixes #5499

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Brian Fromm 2025-11-18 20:29:53 -07:00 committed by Henrique Dias
parent a3b5584505
commit 7bae594138
3 changed files with 13 additions and 1 deletions

View File

@ -102,6 +102,7 @@
"username": "Username",
"usernameTaken": "Username already taken",
"wrongCredentials": "Wrong credentials",
"passwordTooShort": "Password must be at least {min} characters",
"logout_reasons": {
"inactivity": "You have been logged out due to inactivity."
}

View File

@ -101,7 +101,11 @@ export async function signup(username: string, password: string) {
});
if (res.status !== 200) {
throw new StatusError(`${res.status} ${res.statusText}`, res.status);
const body = await res.text();
throw new StatusError(
body || `${res.status} ${res.statusText}`,
res.status
);
}
}

View File

@ -112,6 +112,13 @@ const submit = async (event: Event) => {
error.value = t("login.usernameTaken");
} else if (e.status === 403) {
error.value = t("login.wrongCredentials");
} else if (e.status === 400) {
const match = e.message.match(/minimum length is (\d+)/);
if (match) {
error.value = t("login.passwordTooShort", { min: match[1] });
} else {
error.value = e.message;
}
} else {
$showError(e);
}