Request contexts and some logging changes. #10

Merged
skobkin merged 3 commits from fix_logging into main 2024-03-12 03:15:55 +00:00
Showing only changes of commit 118693d4e4 - Show all commits

View file

@ -114,6 +114,8 @@ func (b *Bot) heyHandler(bot *telego.Bot, update telego.Update) {
if err != nil { if err != nil {
slog.Error("Can't send reply message", err) slog.Error("Can't send reply message", err)
b.trySendReplyError(update.Message)
} }
} }
@ -179,6 +181,8 @@ func (b *Bot) summarizeHandler(bot *telego.Bot, update telego.Update) {
if err != nil { if err != nil {
slog.Error("Can't send reply message", err) slog.Error("Can't send reply message", err)
b.trySendReplyError(update.Message)
} }
} }
@ -198,6 +202,8 @@ func (b *Bot) helpHandler(bot *telego.Bot, update telego.Update) {
))) )))
if err != nil { if err != nil {
slog.Error("Cannot send a message", err) slog.Error("Cannot send a message", err)
b.trySendReplyError(update.Message)
} }
} }
@ -215,6 +221,8 @@ func (b *Bot) startHandler(bot *telego.Bot, update telego.Update) {
))) )))
if err != nil { if err != nil {
slog.Error("Cannot send a message", err) slog.Error("Cannot send a message", err)
b.trySendReplyError(update.Message)
} }
} }
@ -234,6 +242,8 @@ func (b *Bot) statsHandler(bot *telego.Bot, update telego.Update) {
)).WithParseMode("Markdown")) )).WithParseMode("Markdown"))
if err != nil { if err != nil {
slog.Error("Cannot send a message", err) slog.Error("Cannot send a message", err)
b.trySendReplyError(update.Message)
} }
} }
@ -251,3 +261,14 @@ func (b *Bot) sendTyping(chatId telego.ChatID) {
slog.Error("Cannot set chat action", err) slog.Error("Cannot set chat action", err)
} }
} }
func (b *Bot) trySendReplyError(message *telego.Message) {
if message == nil {
return
}
_, _ = b.api.SendMessage(b.reply(message, tu.Message(
tu.ID(message.Chat.ID),
"Error occurred while trying to send reply.",
)))
}