diff --git a/notification/send.go b/notification/send.go index 1b8d2efb..82e82628 100644 --- a/notification/send.go +++ b/notification/send.go @@ -161,7 +161,7 @@ func SendNotification(ctx *Context, connectionName, shoutrrrURL string, celEnv m } if err := SlackSend(ctx, connection.Password, connection.Username, data); err != nil { - return "", ctx.Oops().Hint(data.Message).Wrap(err) + return "", err } return "slack", nil diff --git a/notification/slack.go b/notification/slack.go index cd95cead..6950233a 100644 --- a/notification/slack.go +++ b/notification/slack.go @@ -2,6 +2,7 @@ package notification import ( "encoding/json" + "errors" "fmt" "strings" @@ -13,6 +14,10 @@ type SlackMsgTemplate struct { } func SlackSend(ctx *Context, apiToken, channel string, msg NotificationTemplate) error { + if channel == "" { + return errors.New("slack channel cannot be empty") + } + api := slack.New(apiToken) var opts []slack.MsgOption @@ -34,5 +39,14 @@ func SlackSend(ctx *Context, apiToken, channel string, msg NotificationTemplate) } _, _, err := api.PostMessage(channel, opts...) - return err + + var slackError slack.SlackErrorResponse + if errors.As(err, &slackError) { + switch slackError.Err { + case "channel_not_found": + return fmt.Errorf("slack channel %q not found. ensure the channel exists & the bot has permission on that channel", channel) + } + } + + return ctx.Oops().Hint(msg.Message).Wrap(err) }