Skip to content

Commit 67ef5a5

Browse files
committed
Backend: rename the authentication errors to be more generic.
1 parent 87518a4 commit 67ef5a5

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

backend/db/session.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
)
1313

1414
var (
15-
AuthenticateErrCredentials = errors.New("invalid credentials")
16-
AuthenticateErrQuery = errors.New("failed to query the user")
15+
Unathorized = errors.New("unauthorized")
16+
InternalServerError = errors.New("internal server error")
1717
)
1818

1919
func Authenticate(username string, password string) (int, error) {
@@ -24,15 +24,15 @@ func Authenticate(username string, password string) (int, error) {
2424
err := db.QueryRow(query, username).Scan(&userID, &hashedPassword)
2525
if err != nil {
2626
if err == sql.ErrNoRows {
27-
return -1, AuthenticateErrCredentials
27+
return -1, Unathorized
2828
}
2929
log.Println(err)
30-
return -1, AuthenticateErrQuery
30+
return -1, InternalServerError
3131
}
3232

3333
err = bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password))
3434
if err != nil {
35-
return -1, AuthenticateErrCredentials
35+
return -1, Unathorized
3636
}
3737

3838
return userID, nil

backend/server/session.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ func (handler *sessionHandler) handlePost(writer http.ResponseWriter, request *h
3030
}
3131

3232
userID, err := db.Authenticate(credentials.Username, credentials.Password)
33-
if err == db.AuthenticateErrCredentials {
33+
if err == db.Unathorized {
3434
http.Error(writer, err.Error(), http.StatusUnauthorized)
3535
return
36-
} else if err == db.AuthenticateErrQuery {
36+
} else if err == db.InternalServerError {
3737
http.Error(writer, err.Error(), http.StatusInternalServerError)
3838
return
3939
}

0 commit comments

Comments
 (0)