This commit is contained in:
@@ -3,6 +3,7 @@ package handler
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
@@ -20,7 +21,12 @@ func (h *Handler) Fallback(w http.ResponseWriter, r *http.Request) {
|
|||||||
// Pretty-print JSON to console
|
// Pretty-print JSON to console
|
||||||
var prettyJSON bytes.Buffer
|
var prettyJSON bytes.Buffer
|
||||||
if err := json.Indent(&prettyJSON, body, "", " "); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user