log more info in fallback function
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-03-24 21:26:11 +11:00
parent 8112cd08c4
commit d750033efd

View File

@@ -9,7 +9,21 @@ import (
)
func (h *Handler) Fallback(w http.ResponseWriter, r *http.Request) {
h.Logger.Debug("Fallback Request received", "method", r.Method, "path", r.URL.Path)
h.Logger.Debug("Fallback Request received", "method", r.Method, "url", r.URL, "path", r.URL.Path, "query", r.URL.Query(), "proto", r.Proto)
// Print headers
for name, values := range r.Header {
for _, value := range values {
h.Logger.Debug("Header ", "name", name, "value", value)
}
}
// print query
for key, values := range r.URL.Query() {
for _, value := range values {
h.Logger.Debug("Query Paramater", "key", key, "value", value)
}
}
body, err := io.ReadAll(r.Body)
if err != nil {
@@ -22,7 +36,8 @@ func (h *Handler) Fallback(w http.ResponseWriter, r *http.Request) {
var prettyJSON bytes.Buffer
if err := json.Indent(&prettyJSON, body, "", " "); err != nil {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusBadRequest)
// always send 200 just so that the requestor doesn't error out
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]string{
"status": "ERROR",
"message": fmt.Sprintf("Invalid JSON received. Visit /about for more info."),