From 8112cd08c4e5542940e4b466638e09f1a0a1fddc Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Mon, 24 Mar 2025 17:46:25 +1100 Subject: [PATCH] return proper json --- server/handler/fallback.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/handler/fallback.go b/server/handler/fallback.go index 22b3f19..3334b50 100644 --- a/server/handler/fallback.go +++ b/server/handler/fallback.go @@ -3,6 +3,7 @@ package handler import ( "bytes" "encoding/json" + "fmt" "io" "net/http" ) @@ -20,7 +21,12 @@ func (h *Handler) Fallback(w http.ResponseWriter, r *http.Request) { // Pretty-print JSON to console var prettyJSON bytes.Buffer if err := json.Indent(&prettyJSON, body, "", " "); err != nil { - http.Error(w, "Invalid JSON", http.StatusBadRequest) + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusBadRequest) + json.NewEncoder(w).Encode(map[string]string{ + "status": "ERROR", + "message": fmt.Sprintf("Invalid JSON received. Visit /about for more info."), + }) return }