diff options
| author | Horus3 | 2015-03-30 18:40:44 +0200 |
|---|---|---|
| committer | Horus3 | 2015-03-30 18:40:44 +0200 |
| commit | 9bb67e86806b38a5ecf98f9844048c675ef14d40 (patch) | |
| tree | 8d65fe038ba2ec09674a36a56c994749d78e8dcc | |
| parent | 28628bb02221c63363144904d9966cf9fc8146f4 (diff) | |
| download | web2irc-9bb67e86806b38a5ecf98f9844048c675ef14d40.tar.gz | |
Logs request body when parsing to JSON failed.
| -rw-r--r-- | handler.go | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -2,6 +2,7 @@ package main import ( "encoding/json" + "io/ioutil" "log" "net/http" "os" @@ -21,12 +22,23 @@ func WebhookFailureHandler(w http.ResponseWriter, r *http.Request) { func WebhookHandler(w http.ResponseWriter, r *http.Request) { decoder := json.NewDecoder(r.Body) + var hook Webhook + defer r.Body.Close() + err := decoder.Decode(&hook) if err != nil { - log.Print("Wrong JSON.", err) + + content, err := ioutil.ReadAll(r.Body) + if err != nil { + log.Println("Can't read r.Body.", err) + } + body := string(content) + + log.Print("Wrong JSON.", err, "Original message: "+body) + w.WriteHeader(400) - w.Write([]byte("Wrong JSON.")) + w.Write([]byte("Wrong JSON. " + err.Error() + " Original message: " + body)) return } if hook.Join != "" { |
