return proper json
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-03-24 17:46:25 +11:00
parent 252bf0a1c8
commit 8112cd08c4

View File

@@ -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
}