Properly handle error and improve error messages

This commit is contained in:
2024-09-21 11:26:25 +07:00
parent 557e7313b2
commit bcdcbd5049
25 changed files with 258 additions and 234 deletions

View File

@ -20,9 +20,8 @@ import (
)
type UnverifiedUser struct {
User *models.User
Code string
CreateTime time.Time
User *models.User
Code string
}
func GET(w http.ResponseWriter, r *http.Request) {
@ -36,6 +35,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
app.Server.Logger.Error(err.Error())
return
}
return
}
func POST(w http.ResponseWriter, r *http.Request) {
@ -123,9 +123,8 @@ func verifyEmail(user *models.User) error {
}
unverifiedUser := UnverifiedUser{
User: user,
Code: code,
CreateTime: time.Now(),
User: user,
Code: code,
}
newUnverifiedUser, err := json.Marshal(unverifiedUser)
if err != nil {

View File

@ -15,7 +15,6 @@ import (
func GET(w http.ResponseWriter, r *http.Request) {
code := r.PathValue("code")
userDataStr, err := app.Server.Cache.GetCache(context.Background(), "UnverifiedUser:"+code)
if err != nil {
if errors.Is(err, redis.Nil) {
@ -53,11 +52,15 @@ func GET(w http.ResponseWriter, r *http.Request) {
err = app.Server.Cache.DeleteCache(context.Background(), "UnverifiedUser:"+code)
if err != nil {
app.Server.Logger.Error(err.Error())
w.WriteHeader(http.StatusInternalServerError)
return
}
err = app.Server.Cache.DeleteCache(context.Background(), "VerificationCode:"+unverifiedUser.User.Email)
if err != nil {
app.Server.Logger.Error(err.Error())
w.WriteHeader(http.StatusInternalServerError)
return
}
component := signupView.VerifySuccess("Filekeeper - Verify Page")
@ -67,4 +70,5 @@ func GET(w http.ResponseWriter, r *http.Request) {
app.Server.Logger.Error(err.Error())
return
}
return
}