From b4249c7f38b6b73d126250c8d4c2a37ef7a9ef1f Mon Sep 17 00:00:00 2001 From: smanylov Date: Fri, 30 Jan 2026 23:02:18 +0700 Subject: [PATCH] add error handler --- src/app/actions/auth.ts | 25 +++++++++++++++---------- src/i18n/messages/en.json | 3 ++- src/i18n/messages/ru.json | 3 ++- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/app/actions/auth.ts b/src/app/actions/auth.ts index 6d22583..5f7b474 100644 --- a/src/app/actions/auth.ts +++ b/src/app/actions/auth.ts @@ -259,16 +259,21 @@ export async function registration( break; case 2: - typedError.message_body.fieldErrors.forEach((obj: { - code: string, - field: string - }) => { - if (errors[obj.field]) { - errors[obj.field] = `${errors[obj.field]}&${obj.code.replaceAll('.', '-')}`; - } else { - errors[obj.field] = obj.code.replaceAll('.', '-'); - } - }); + if (typedError.message_body?.fieldErrors) { + typedError.message_body?.fieldErrors?.forEach((obj: { + code: string, + field: string + }) => { + if (errors[obj.field]) { + errors[obj.field] = `${errors[obj.field]}&${obj.code.replaceAll('.', '-')}`; + } else { + errors[obj.field] = obj.code.replaceAll('.', '-'); + } + }); + + } else { + errors['server'] = 'unknown-error' + } break; default: diff --git a/src/i18n/messages/en.json b/src/i18n/messages/en.json index f9c2f28..b222f6b 100644 --- a/src/i18n/messages/en.json +++ b/src/i18n/messages/en.json @@ -274,6 +274,7 @@ "register-error-password-not-allowed-symbols": "Password contains invalid characters.", "confirmation-code": "Confirmation code", "enter-confirmation-code": "Enter the confirmation code", - "personal": "Personal" + "personal": "Personal", + "unknown-error": "Unknown error" } } \ No newline at end of file diff --git a/src/i18n/messages/ru.json b/src/i18n/messages/ru.json index 93840c7..527aad1 100644 --- a/src/i18n/messages/ru.json +++ b/src/i18n/messages/ru.json @@ -274,6 +274,7 @@ "register-error-password-not-allowed-symbols": "Пароль содержит недопустимые символы.", "confirmation-code": "Код подтверждения", "enter-confirmation-code": "Введите код подтверждения", - "personal": "Личный" + "personal": "Личный", + "unknown-error": "Неизвестная ошибка" } } \ No newline at end of file