summaryrefslogtreecommitdiff
path: root/internal/api/handlers_admin.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-10 09:43:39 +0300
committerPaul Buetow <paul@buetow.org>2026-05-10 09:43:39 +0300
commit8b58c8c90f71eb0b11ad47202692dc4ab80d34d4 (patch)
tree7ac8ccaefc8c9ac9100e9b279b686a7b85105ff6 /internal/api/handlers_admin.go
parent83cd87a04f65229346cb4f77f56eba5da0c668c1 (diff)
refactor(api): replace all writeJSON 500 error patterns with handleError helper
Diffstat (limited to 'internal/api/handlers_admin.go')
-rw-r--r--internal/api/handlers_admin.go16
1 files changed, 8 insertions, 8 deletions
diff --git a/internal/api/handlers_admin.go b/internal/api/handlers_admin.go
index b1c3005..77e5b9f 100644
--- a/internal/api/handlers_admin.go
+++ b/internal/api/handlers_admin.go
@@ -16,7 +16,7 @@ func (s *Server) handleListTrash(w http.ResponseWriter, r *http.Request) {
}
items, err := s.adminSvc.ListTrash(r.Context())
if err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
+ handleError(w, err)
return
}
writeJSON(w, http.StatusOK, items)
@@ -27,7 +27,7 @@ func (s *Server) handleRescan(w http.ResponseWriter, r *http.Request) {
return
}
if err := s.adminSvc.TriggerRescan(r.Context()); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
+ handleError(w, err)
return
}
writeJSON(w, http.StatusOK, map[string]string{"status": "ok"})
@@ -46,7 +46,7 @@ func (s *Server) handleListUsers(w http.ResponseWriter, r *http.Request) {
}
users, err := s.adminSvc.ListUsers(r.Context())
if err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
+ handleError(w, err)
return
}
writeJSON(w, http.StatusOK, users)
@@ -67,7 +67,7 @@ func (s *Server) handleCreateUser(w http.ResponseWriter, r *http.Request) {
}
user, err := s.adminSvc.CreateUser(r.Context(), req.Username, req.Password, req.IsAdmin)
if err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
+ handleError(w, err)
return
}
writeJSON(w, http.StatusOK, user)
@@ -84,7 +84,7 @@ func (s *Server) handleDeleteUser(w http.ResponseWriter, r *http.Request) {
return
}
if err := s.adminSvc.DeleteUser(r.Context(), id); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
+ handleError(w, err)
return
}
writeJSON(w, http.StatusOK, map[string]string{"status": "ok"})
@@ -96,7 +96,7 @@ func (s *Server) handleListPermissions(w http.ResponseWriter, r *http.Request) {
}
perms, err := s.adminSvc.ListPermissions(r.Context())
if err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
+ handleError(w, err)
return
}
writeJSON(w, http.StatusOK, perms)
@@ -116,7 +116,7 @@ func (s *Server) handleGrantPermission(w http.ResponseWriter, r *http.Request) {
return
}
if err := s.adminSvc.GrantPermission(r.Context(), req.SetID, req.UserID, req.Role); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
+ handleError(w, err)
return
}
writeJSON(w, http.StatusOK, map[string]string{"status": "ok"})
@@ -135,7 +135,7 @@ func (s *Server) handleRevokePermission(w http.ResponseWriter, r *http.Request)
return
}
if err := s.adminSvc.RevokePermission(r.Context(), req.SetID, req.UserID); err != nil {
- writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
+ handleError(w, err)
return
}
writeJSON(w, http.StatusOK, map[string]string{"status": "ok"})