Improvements to enforce middleware, linting, returning 404 properly

This commit is contained in:
Jamie Curnow
2024-09-11 15:03:00 +10:00
parent 833dd23dce
commit 9a2e5c92d5
18 changed files with 110 additions and 104 deletions

View File

@ -11,6 +11,8 @@ import (
"npm/internal/entity/user"
"npm/internal/errors"
"npm/internal/logger"
"gorm.io/gorm"
)
type setAuthModel struct {
@ -41,7 +43,10 @@ func SetAuth() func(http.ResponseWriter, *http.Request) {
// Load user
thisUser, thisUserErr := user.GetByID(userID)
if thisUserErr != nil {
if thisUserErr == gorm.ErrRecordNotFound {
h.NotFound(w, r)
return
} else if thisUserErr != nil {
h.ResultErrorJSON(w, r, http.StatusBadRequest, thisUserErr.Error(), nil)
return
}