Skip to content

Commit

Permalink
automod: handle slack webhook errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bnewbold committed Dec 9, 2023
1 parent 7f4f787 commit c479e33
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions automod/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ type SlackWebhookBody struct {
func (e *Engine) SendSlackMsg(ctx context.Context, msg string) error {
// loosely based on: https://golangcode.com/send-slack-messages-without-a-library/

body, _ := json.Marshal(SlackWebhookBody{Text: msg})
body, err := json.Marshal(SlackWebhookBody{Text: msg})
if err != nil {
return err
}
req, err := http.NewRequestWithContext(ctx, http.MethodPost, e.SlackWebhookURL, bytes.NewBuffer(body))
if err != nil {
return err
Expand All @@ -35,7 +38,6 @@ func (e *Engine) SendSlackMsg(ctx context.Context, msg string) error {
buf := new(bytes.Buffer)
buf.ReadFrom(resp.Body)
if resp.StatusCode != 200 || buf.String() != "ok" {
// TODO: in some cases print body? eg, if short and text
return fmt.Errorf("failed slack webhook POST request. status=%d", resp.StatusCode)
}
return nil
Expand Down

0 comments on commit c479e33

Please sign in to comment.