Skip to content

Commit

Permalink
updating errors for login handler
Browse files Browse the repository at this point in the history
  • Loading branch information
makhlouf1102 committed Jan 9, 2025
1 parent 16ebdc5 commit 7f9227a
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions handlers/auth/authHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"lets-go/libs/bcrypt"
commonerrors "lets-go/libs/commonErrors"
localconstants "lets-go/libs/localConstants"
loglib "lets-go/libs/logLib"
role_model "lets-go/models/role"
userModel "lets-go/models/user"
Expand Down Expand Up @@ -94,7 +93,7 @@ func Login(w http.ResponseWriter, r *http.Request) {

if err != nil {
loglib.LogError("invalid login", err)
http.Error(w, localconstants.UNAUTHORIZED, http.StatusUnauthorized)
commonerrors.HttpErrorWithMessage(w, err, http.StatusUnauthorized, "invalid login")
return
}

Expand All @@ -107,16 +106,14 @@ func Login(w http.ResponseWriter, r *http.Request) {
}

if err != nil {
loglib.LogError("error while setting up the roles", err)
http.Error(w, localconstants.SERVER_ERROR, http.StatusInternalServerError)
commonerrors.HttpErrorWithMessage(w, err, http.StatusInternalServerError, "server error while setting up the roles")
return
}

tokens, err := generateTokens(user.ID, listRoles)

if err != nil {
loglib.LogError("error while creating tokens", err)
http.Error(w, localconstants.SERVER_ERROR, http.StatusInternalServerError)
commonerrors.HttpErrorWithMessage(w, err, http.StatusInternalServerError, "server error while creating tokens")
return
}

Expand Down

0 comments on commit 7f9227a

Please sign in to comment.