diff --git a/.changelog/106.txt b/.changelog/106.txt new file mode 100644 index 0000000..4d48a6f --- /dev/null +++ b/.changelog/106.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +webhook output: Log response body when webhook push fails. +``` diff --git a/internal/output/webhook/webhook.go b/internal/output/webhook/webhook.go index 4495869..19af7cc 100644 --- a/internal/output/webhook/webhook.go +++ b/internal/output/webhook/webhook.go @@ -9,6 +9,7 @@ import ( "context" "crypto/tls" "fmt" + "io" "net/http" "net/url" "strings" @@ -94,10 +95,15 @@ func (o *Output) Write(b []byte) (int, error) { if err != nil { return 0, err } + var buf bytes.Buffer + io.Copy(&buf, resp.Body) defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - return 0, fmt.Errorf("http post to webhook failed with http status %v %v", resp.StatusCode, resp.Status) + if buf.Len() == 0 { + buf.WriteString("no body") + } + return 0, fmt.Errorf("http post to webhook failed with http status %v %v: %s", resp.StatusCode, resp.Status, &buf) } return len(b), nil