fix: db errors are now handled correctly

This commit is contained in:
HerozDotExe 2025-08-05 15:19:36 +02:00
parent 9568470610
commit ef752d9add
2 changed files with 18 additions and 8 deletions

View file

@ -41,7 +41,7 @@
}
function handleDBErrors(e: ClientResponseError) {
if (e.data.lenght > 0) {
if (Object.keys(e.data).length > 0) {
const element = Object.keys(e.data.data)[0];
formErrors[element] = true;
const dbError = e.data.data[element];
@ -100,7 +100,7 @@
<div class="grid gap-2">
<div class="flex items-center">
<Label for="password">Password</Label>
<a class="ml-auto inline-block text-sm underline-offset-4 hover:underline">
<a href="/auth/resetPassword" class="ml-auto inline-block text-sm underline-offset-4 hover:underline cursor-pointer">
Forgot your password?
</a>
</div>

View file

@ -53,12 +53,22 @@
}
function handleDBErrors(e: ClientResponseError) {
const element = Object.keys(e.data.data)[0];
formErrors[element] = true;
const dbError = e.data.data[element];
if (dbError.code === 'validation_not_unique') {
error = `This ${element} is already used by someone. Maybe try logging in if it's you.`;
} else error = dbError.message;
console.error(e)
if (Object.keys(e.data).length > 0) {
const element = Object.keys(e.data.data)[0];
formErrors[element] = true;
const dbError = e.data.data[element];
if (dbError.code === 'validation_not_unique') {
error = `This ${element} is already used by someone. Maybe try logging in if it's you.`;
} else error = dbError.message;
} else {
formErrors.email = true;
formErrors.name = true;
formErrors.password = true;
formErrors.passwordConfirm = true;
error = e.message;
}
}
async function register() {