Skip to content

Commit

Permalink
log response body when webhook push fails (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
efd6 authored Jul 5, 2024
1 parent 95fe743 commit bfadcc3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/106.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
webhook output: Log response body when webhook push fails.
```
8 changes: 7 additions & 1 deletion internal/output/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"context"
"crypto/tls"
"fmt"
"io"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bfadcc3

Please sign in to comment.