prevent panic from empty POST payload
This commit is contained in:
parent
ae10b4087a
commit
eacbcfa0a2
8
api.go
8
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()})
|
||||
|
|
Loading…
Reference in New Issue