fix: empty JSON arrays instead of null for alerts/events/runs
CI / go test + web typecheck (push) Canceled after 0s
CI / build + deploy (Nix) — flowsight (push) Canceled after 0s

This commit is contained in:
asepharyana
2026-09-15 15:44:27 +07:00
parent 9a441c71a6
commit fee313ce97
2 changed files with 11 additions and 0 deletions
+8
View File
@@ -5,6 +5,8 @@ import (
"net/http" "net/http"
"strconv" "strconv"
"flowsight/internal/store"
"github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5"
) )
@@ -15,6 +17,9 @@ func (s *Server) ListAlerts(w http.ResponseWriter, r *http.Request) {
writeErr(w, http.StatusBadGateway, "db: "+err.Error()) writeErr(w, http.StatusBadGateway, "db: "+err.Error())
return return
} }
if rows == nil {
rows = []store.Alert{}
}
writeJSON(w, http.StatusOK, map[string]any{"alerts": rows}) writeJSON(w, http.StatusOK, map[string]any{"alerts": rows})
} }
@@ -72,5 +77,8 @@ func (s *Server) AlertEvents(w http.ResponseWriter, r *http.Request) {
writeErr(w, http.StatusBadGateway, "db: "+err.Error()) writeErr(w, http.StatusBadGateway, "db: "+err.Error())
return return
} }
if evts == nil {
evts = []map[string]any{}
}
writeJSON(w, http.StatusOK, map[string]any{"events": evts}) writeJSON(w, http.StatusOK, map[string]any{"events": evts})
} }
+3
View File
@@ -101,6 +101,9 @@ func (s *Server) RunHistory(w http.ResponseWriter, r *http.Request) {
writeErr(w, http.StatusBadGateway, "db: "+err.Error()) writeErr(w, http.StatusBadGateway, "db: "+err.Error())
return return
} }
if hist == nil {
hist = []map[string]any{}
}
writeJSON(w, http.StatusOK, map[string]any{"runs": hist}) writeJSON(w, http.StatusOK, map[string]any{"runs": hist})
} }