This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user