From e3ebbe596c6b496eed702f890d8ec2b45c879555 Mon Sep 17 00:00:00 2001 From: Alex <$(pass /github/email)> Date: Fri, 28 Feb 2025 11:56:53 +0100 Subject: [PATCH] errors: handling, locale --- frontend/src/lib/locales/de.js | 4 +- go-backend/internal/utils/response_handler.go | 14 +++++ go-backend/pkg/errors/errors.go | 54 ++++++++++--------- 3 files changed, 45 insertions(+), 27 deletions(-) diff --git a/frontend/src/lib/locales/de.js b/frontend/src/lib/locales/de.js index 01e508c..8441c0e 100644 --- a/frontend/src/lib/locales/de.js +++ b/frontend/src/lib/locales/de.js @@ -61,7 +61,9 @@ export default { 'Verdammt, Fehler auf unserer Seite, probieren Sie es nochmal, danach rufen Sie jemanden vom Verein an.', not_possible: 'Vorgang nicht möglich.', not_found: 'Konnte nicht gefunden werden.', - in_use: 'Ist in Benutzung' + in_use: 'Ist in Benutzung', + undelivered_verification_mail: + 'Registrierung erfolgreicht, leider konnte die Verifizierungs-E-Mail nicht versendet werden. Bitte wenden Sie sich an den Verein um Ihre Emailadresse zu bestätigen und Ihren Account zu aktivieren.' }, validation: { invalid_user_id: 'Nutzer ID ungültig', diff --git a/go-backend/internal/utils/response_handler.go b/go-backend/internal/utils/response_handler.go index 02be255..ef9810f 100644 --- a/go-backend/internal/utils/response_handler.go +++ b/go-backend/internal/utils/response_handler.go @@ -92,3 +92,17 @@ func HandleVerifyUserError(c *gin.Context, err error) { RespondWithError(c, err, "Couldn't verify user", http.StatusInternalServerError, errors.Responses.Fields.General, errors.Responses.Keys.InternalServerError) } } + +func HandleDeleteUserError(c *gin.Context, err error) { + if err.Error() == "record not found" { + RespondWithError(c, err, "Couldn't find user", http.StatusNotFound, errors.Responses.Fields.User, errors.Responses.Keys.NotFound) + } + switch err { + case errors.ErrUserNotFound: + RespondWithError(c, err, "User not found", http.StatusNotFound, errors.Responses.Fields.User, errors.Responses.Keys.NotFound) + case errors.ErrNoData: + RespondWithError(c, err, "No data transmitted", http.StatusNotFound, errors.Responses.Fields.User, errors.Responses.Keys.Invalid) + default: + RespondWithError(c, err, "Couldn't delete user", http.StatusInternalServerError, errors.Responses.Fields.User, errors.Responses.Keys.InternalServerError) + } +} diff --git a/go-backend/pkg/errors/errors.go b/go-backend/pkg/errors/errors.go index b7fc3a2..60a4a55 100644 --- a/go-backend/pkg/errors/errors.go +++ b/go-backend/pkg/errors/errors.go @@ -3,20 +3,21 @@ package errors import "errors" type ValidationKeys struct { - Invalid string - InternalServerError string - InvalidJson string - Unauthorized string - InvalidSubscriptionModel string - UserNotFoundWrongPassword string - JwtGenerationFailed string - Duplicate string - InvalidUserID string - PasswordAlreadyChanged string - UserDisabled string - NoAuthToken string - NotFound string - InUse string + Invalid string + InternalServerError string + InvalidJson string + Unauthorized string + InvalidSubscriptionModel string + UserNotFoundWrongPassword string + JwtGenerationFailed string + Duplicate string + InvalidUserID string + PasswordAlreadyChanged string + UserDisabled string + NoAuthToken string + NotFound string + InUse string + UndeliveredVerificationMail string } type ValidationFields struct { @@ -58,18 +59,19 @@ var Responses = struct { Fields ValidationFields }{ Keys: ValidationKeys{ - Invalid: "server.validation.invalid", - InternalServerError: "server.error.internal_server_error", - InvalidJson: "server.error.invalid_json", - Unauthorized: "server.error.unauthorized", - UserNotFoundWrongPassword: "server.validation.user_not_found_or_wrong_password", - JwtGenerationFailed: "server.error.jwt_generation_failed", - Duplicate: "server.validation.duplicate", - UserDisabled: "server.validation.user_disabled", - PasswordAlreadyChanged: "server.validation.password_already_changed", - NoAuthToken: "server.error.no_auth_token", - NotFound: "server.error.not_found", - InUse: "server.error.in_use", + Invalid: "server.validation.invalid", + InternalServerError: "server.error.internal_server_error", + InvalidJson: "server.error.invalid_json", + Unauthorized: "server.error.unauthorized", + UserNotFoundWrongPassword: "server.validation.user_not_found_or_wrong_password", + JwtGenerationFailed: "server.error.jwt_generation_failed", + Duplicate: "server.validation.duplicate", + UserDisabled: "server.validation.user_disabled", + PasswordAlreadyChanged: "server.validation.password_already_changed", + NoAuthToken: "server.error.no_auth_token", + NotFound: "server.error.not_found", + InUse: "server.error.in_use", + UndeliveredVerificationMail: "server.error.undelivered_verification_mail", }, Fields: ValidationFields{ General: "general",