Skip to content

Commit

Permalink
log response body when webhook push fails
Browse files Browse the repository at this point in the history
  • Loading branch information
efd6 committed Jul 5, 2024
1 parent 95fe743 commit ffe3430
Showing 1 changed file with 7 additions and 1 deletion.
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)

Check failure on line 99 in internal/output/webhook/webhook.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `io.Copy` is not checked (errcheck)
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 ffe3430

Please sign in to comment.