log more info in fallback function
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -9,7 +9,21 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (h *Handler) Fallback(w http.ResponseWriter, r *http.Request) {
|
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)
|
body, err := io.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -22,7 +36,8 @@ func (h *Handler) Fallback(w http.ResponseWriter, r *http.Request) {
|
|||||||
var prettyJSON bytes.Buffer
|
var prettyJSON bytes.Buffer
|
||||||
if err := json.Indent(&prettyJSON, body, "", " "); err != nil {
|
if err := json.Indent(&prettyJSON, body, "", " "); err != nil {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
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{
|
json.NewEncoder(w).Encode(map[string]string{
|
||||||
"status": "ERROR",
|
"status": "ERROR",
|
||||||
"message": fmt.Sprintf("Invalid JSON received. Visit /about for more info."),
|
"message": fmt.Sprintf("Invalid JSON received. Visit /about for more info."),
|
||||||
|
Reference in New Issue
Block a user