Compare commits

..

3 Commits

Author SHA1 Message Date
Derrick Hammer 4ca78df050
refactor: use ErrKeySecurityInvalidToken 2024-03-26 20:25:32 -04:00
Derrick Hammer adc5bc213e
Revert "fix: add error for email verification"
This reverts commit ea5a97c6
2024-03-26 20:24:55 -04:00
Derrick Hammer 501de26793
fix: update error 2024-03-26 20:22:53 -04:00
3 changed files with 9 additions and 12 deletions

View File

@ -202,10 +202,10 @@ func (s AccountServiceDefault) VerifyEmail(email string, token string) error {
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return NewAccountError(ErrKeyEmailVerificationFailed, nil) return NewAccountError(ErrKeyUserNotFound, nil)
} }
return NewAccountError(ErrKeyDatabaseOperationFailed, result.Error) return NewAccountError(ErrKeySecurityInvalidToken, nil)
} }
if verification.ExpiresAt.Before(time.Now()) { if verification.ExpiresAt.Before(time.Now()) {

View File

@ -25,9 +25,8 @@ const (
ErrKeyHashingFailed = "ErrHashingFailed" ErrKeyHashingFailed = "ErrHashingFailed"
// Account update errors // Account update errors
ErrKeyAccountUpdateFailed = "ErrAccountUpdateFailed" ErrKeyAccountUpdateFailed = "ErrAccountUpdateFailed"
ErrKeyAccountAlreadyVerified = "ErrAccountAlreadyVerified" ErrKeyAccountAlreadyVerified = "ErrAccountAlreadyVerified"
ErrKeyEmailVerificationFailed = "ErrEmailVerificationFailed"
// JWT generation errors // JWT generation errors
ErrKeyJWTGenerationFailed = "ErrJWTGenerationFailed" ErrKeyJWTGenerationFailed = "ErrJWTGenerationFailed"
@ -74,9 +73,8 @@ var defaultErrorMessages = map[string]string{
ErrKeyLoginFailed: "Login failed due to an internal error.", ErrKeyLoginFailed: "Login failed due to an internal error.",
// Account update errors // Account update errors
ErrKeyAccountUpdateFailed: "Failed to update account information.", ErrKeyAccountUpdateFailed: "Failed to update account information.",
ErrKeyAccountAlreadyVerified: "Account is already verified.", ErrKeyAccountAlreadyVerified: "Account is already verified.",
ErrKeyEmailVerificationFailed: "Failed to verify email address.",
// JWT generation errors // JWT generation errors
ErrKeyJWTGenerationFailed: "Failed to generate a new JWT token.", ErrKeyJWTGenerationFailed: "Failed to generate a new JWT token.",
@ -122,9 +120,8 @@ var (
ErrKeyLoginFailed: http.StatusInternalServerError, ErrKeyLoginFailed: http.StatusInternalServerError,
// Account update errors // Account update errors
ErrKeyAccountUpdateFailed: http.StatusInternalServerError, ErrKeyAccountUpdateFailed: http.StatusInternalServerError,
ErrKeyAccountAlreadyVerified: http.StatusConflict, ErrKeyAccountAlreadyVerified: http.StatusConflict,
ErrKeyEmailVerificationFailed: http.StatusInternalServerError,
// JWT generation errors // JWT generation errors
ErrKeyJWTGenerationFailed: http.StatusInternalServerError, ErrKeyJWTGenerationFailed: http.StatusInternalServerError,

View File

@ -172,7 +172,7 @@ func (a AccountAPI) verifyEmail(jc jape.Context) {
err := a.accounts.VerifyEmail(request.Email, request.Token) err := a.accounts.VerifyEmail(request.Email, request.Token)
if jc.Check("failed to verify email", err) != nil { if jc.Check("Failed to verify email", err) != nil {
return return
} }
} }