From eacbcfa0a25ce51f1f9cabb2ef7b9c6f663bd01b Mon Sep 17 00:00:00 2001 From: Stephen McQuay Date: Sat, 21 Dec 2013 01:27:33 -0800 Subject: [PATCH] prevent panic from empty POST payload --- api.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/api.go b/api.go index 9197b0c..f068514 100644 --- a/api.go +++ b/api.go @@ -56,6 +56,14 @@ func put(w http.ResponseWriter, req *http.Request) { if *verbose { log.Printf("incoming: '%s'", body) } + // XXX: I am going to posit that there is something funky with how I write + // the error out below; If I don't check this, and I get to the + // JSONError{err.Error()} below then the app panics. + if string(body) == "" { + b, _ := json.Marshal(JSONError{"empty body"}) + http.Error(w, string(b), http.StatusMethodNotAllowed) + return + } parse_err := json.Unmarshal(body, &message) if parse_err != nil { b, _ := json.Marshal(JSONError{err.Error()})