From c479e333a6f1d980c8061a3a094a0fe5e77a30b4 Mon Sep 17 00:00:00 2001 From: bryan newbold Date: Sat, 9 Dec 2023 14:12:54 +0800 Subject: [PATCH] automod: handle slack webhook errors --- automod/slack.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/automod/slack.go b/automod/slack.go index 6191452fc..04ceee9d0 100644 --- a/automod/slack.go +++ b/automod/slack.go @@ -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 @@ -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