diff --git a/web/webhook.go b/web/webhook.go index 65f8a1e682..07f59e7fbb 100644 --- a/web/webhook.go +++ b/web/webhook.go @@ -4,7 +4,6 @@ package web import ( - "fmt" "io" "net/http" "strings" @@ -30,6 +29,15 @@ func incomingWebhook(c *Context, w http.ResponseWriter, r *http.Request) { var err *model.AppError incomingWebhookPayload := &model.IncomingWebhookRequest{} contentType := r.Header.Get("Content-Type") + + defer func() { + if *c.App.Config().LogSettings.EnableWebhookDebugging { + if c.Err != nil { + mlog.Debug("Incoming webhook received", mlog.String("webhook_id", id), mlog.String("request_id", c.App.RequestId), mlog.String("payload", incomingWebhookPayload.ToJson())) + } + } + }() + if strings.Split(contentType, "; ")[0] == "application/x-www-form-urlencoded" { payload := strings.NewReader(r.FormValue("payload")) @@ -56,10 +64,6 @@ func incomingWebhook(c *Context, w http.ResponseWriter, r *http.Request) { } } - if *c.App.Config().LogSettings.EnableWebhookDebugging { - mlog.Debug(fmt.Sprintf("Incoming webhook received. Id=%s Content=%s", id, incomingWebhookPayload.ToJson())) - } - err = c.App.HandleIncomingWebhook(id, incomingWebhookPayload) if err != nil { c.Err = err