fix: empty JSON arrays instead of null for alerts/events/runs
This commit is contained in:
@@ -5,6 +5,8 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"flowsight/internal/store"
|
||||
|
||||
"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())
|
||||
return
|
||||
}
|
||||
if rows == nil {
|
||||
rows = []store.Alert{}
|
||||
}
|
||||
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())
|
||||
return
|
||||
}
|
||||
if evts == nil {
|
||||
evts = []map[string]any{}
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{"events": evts})
|
||||
}
|
||||
|
||||
@@ -101,6 +101,9 @@ func (s *Server) RunHistory(w http.ResponseWriter, r *http.Request) {
|
||||
writeErr(w, http.StatusBadGateway, "db: "+err.Error())
|
||||
return
|
||||
}
|
||||
if hist == nil {
|
||||
hist = []map[string]any{}
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{"runs": hist})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user