Skip to content
This repository was archived by the owner on May 29, 2024. It is now read-only.

Commit a9250f0

Browse files
committed
Handle error for new telegram client
1 parent 76afa80 commit a9250f0

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

internal/alert/routing.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
package alert
44

55
import (
6+
"go.uber.org/zap"
7+
68
"github.com/base-org/pessimism/internal/client"
79
"github.com/base-org/pessimism/internal/core"
10+
"github.com/base-org/pessimism/internal/logging"
811
)
912

1013
// RoutingDirectory ... Interface for routing directory
@@ -112,7 +115,11 @@ func (rd *routingDirectory) paramsToRouteDirectory(acc *core.AlertClientCfg, sev
112115
ChatID: cfg.ChatID.String(),
113116
Token: cfg.Token.String(),
114117
}
115-
client := client.NewTelegramClient(conf, name)
118+
client, err := client.NewTelegramClient(conf, name)
119+
if err != nil {
120+
logging.NoContext().Error("Failed to create Telegram client", zap.String("name", name), zap.Error(err))
121+
continue
122+
}
116123
rd.telegramClients[sev] = append(rd.telegramClients[sev], client)
117124
}
118125
}

internal/client/telegram.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"encoding/json"
7+
"errors"
78
"fmt"
89
"io"
910
"net/http"
@@ -28,17 +29,18 @@ type telegramClient struct {
2829
client *http.Client
2930
}
3031

31-
func NewTelegramClient(cfg *TelegramConfig, name string) TelegramClient {
32+
func NewTelegramClient(cfg *TelegramConfig, name string) (TelegramClient, error) {
3233
if cfg.Token == "" {
33-
logging.NoContext().Warn("No Telegram token provided")
34+
logging.NoContext().Warn("No Telegram bot token provided")
35+
return nil, errors.New("No Telegram bot token was provided")
3436
}
3537

3638
return &telegramClient{
3739
token: cfg.Token,
3840
chatID: cfg.ChatID,
3941
name: name,
4042
client: &http.Client{},
41-
}
43+
}, nil
4244
}
4345

4446
type TelegramPayload struct {

0 commit comments

Comments
 (0)