summaryrefslogtreecommitdiff
path: root/internal/api/handlers_auth.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-07 00:20:15 +0300
committerPaul Buetow <paul@buetow.org>2026-05-07 00:20:15 +0300
commitd87bcee585883f22b2ca0b42db67bf815cc7c1fc (patch)
treea879c345d3ebaecf526f12d7ad6cf97c6f7f4dba /internal/api/handlers_auth.go
parente1bea8d74391a20201327299481550bf94766236 (diff)
Task 51: add API error helpers
Diffstat (limited to 'internal/api/handlers_auth.go')
-rw-r--r--internal/api/handlers_auth.go10
1 files changed, 5 insertions, 5 deletions
diff --git a/internal/api/handlers_auth.go b/internal/api/handlers_auth.go
index 5bf5f39..b0a1874 100644
--- a/internal/api/handlers_auth.go
+++ b/internal/api/handlers_auth.go
@@ -28,18 +28,18 @@ func (s *Server) handleBootstrap(w http.ResponseWriter, r *http.Request) {
}
var req bootstrapRequest
if err := readJSON(r, &req); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "invalid request body"})
+ badRequest(w, "invalid request body")
return
}
if req.Username == "" || req.Password == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "username and password required"})
+ badRequest(w, "username and password required")
return
}
res, err := s.authSvc.Bootstrap(r.Context(), req.Username, req.Password)
if err != nil {
if errors.Is(err, service.ErrAlreadyBootstrapped) {
- writeJSON(w, http.StatusForbidden, map[string]string{"error": "bootstrap already complete"})
+ forbidden(w, "bootstrap already complete")
return
}
writeJSON(w, http.StatusInternalServerError, map[string]string{"error": "internal server error"})
@@ -56,11 +56,11 @@ func (s *Server) handleLogin(w http.ResponseWriter, r *http.Request) {
}
var req loginRequest
if err := readJSON(r, &req); err != nil {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "invalid request body"})
+ badRequest(w, "invalid request body")
return
}
if req.Username == "" || req.Password == "" {
- writeJSON(w, http.StatusBadRequest, map[string]string{"error": "username and password required"})
+ badRequest(w, "username and password required")
return
}