chore: custom error handler with automatic logging

This commit is contained in:
2025-06-10 17:26:20 +01:00
parent fae46f4bf7
commit 3234e5f4da
9 changed files with 142 additions and 140 deletions
+4 -4
View File
@@ -18,25 +18,25 @@ func (api *API) AuthSessionMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
sess, err := session.Get("session", context)
if err != nil || sess.IsNew {
return context.String(http.StatusUnauthorized, "User not authenticated!")
return types.Error{Code: http.StatusUnauthorized, Messages: []string{"User not authenticated!"}}
}
id, ok := sess.Values["sessionId"].(string)
if !ok || id == "" {
return context.String(http.StatusUnauthorized, "User not authenticated!")
return types.Error{Code: http.StatusUnauthorized, Messages: []string{"User not authenticated!"}}
}
sessionId, err := uuid.Parse(id)
if err != nil {
return context.String(http.StatusUnauthorized, "User not authenticated!")
return types.Error{Code: http.StatusUnauthorized, Messages: []string{"User not authenticated!"}}
}
var user types.User
if err := api.db.GetUserBySessionId(sessionId, &user); err != nil {
return context.String(http.StatusUnauthorized, "User not authenticated!")
return types.Error{Code: http.StatusUnauthorized, Messages: []string{"User not authenticated!"}}
}
context.Set("id", sess.Values["id"])