error handling

This commit is contained in:
Alex
2025-02-28 10:46:40 +01:00
parent b0271f8443
commit a2e8abbf6b
6 changed files with 59 additions and 38 deletions

View File

@@ -24,7 +24,7 @@ func (uc *UserController) RequestPasswordChangeHandler(c *gin.Context) {
// find user
db_user, err := uc.Service.GetUserByEmail(input.Email)
if err != nil {
utils.RespondWithError(c, err, "couldn't get user by email", http.StatusNotFound, "user.user", "user.email")
utils.RespondWithError(c, err, "couldn't get user by email", http.StatusNotFound, errors.Responses.Fields.User, errors.Responses.Keys.NotFound)
return
}
@@ -71,14 +71,7 @@ func (uc *UserController) ChangePassword(c *gin.Context) {
verification, err := uc.Service.VerifyUser(&input.Token, &constants.VerificationTypes.Password)
if err != nil || uint(userIDint) != verification.UserID {
if err == errors.ErrAlreadyVerified {
utils.RespondWithError(c, err, "User already changed password", http.StatusConflict, errors.Responses.Fields.User, errors.Responses.Keys.PasswordAlreadyChanged)
} else if err.Error() == "record not found" {
utils.RespondWithError(c, err, "Couldn't find verification. This is most probably a outdated token.", http.StatusGone, errors.Responses.Fields.User, errors.Responses.Keys.NoAuthToken)
} else {
utils.RespondWithError(c, err, "Couldn't verify user", http.StatusInternalServerError, errors.Responses.Fields.General, errors.Responses.Keys.InternalServerError)
}
utils.HandleVerifyUserError(c, err)
return
}
@@ -95,7 +88,7 @@ func (uc *UserController) ChangePassword(c *gin.Context) {
_, err = uc.Service.UpdateUser(user)
if err != nil {
utils.RespondWithError(c, err, "Couldn't update user", http.StatusInternalServerError, errors.Responses.Fields.User, errors.Responses.Keys.InternalServerError)
utils.HandleUserUpdateError(c, err)
return
}