Skip to content

Commit

Permalink
bot: set backup OnError if such was not passed
Browse files Browse the repository at this point in the history
  • Loading branch information
demget committed Jan 21, 2022
1 parent 3a6cb71 commit b14a065
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 3 additions & 0 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func NewBot(pref Settings) (*Bot, error) {
if pref.Poller == nil {
pref.Poller = &LongPoller{}
}
if pref.OnError == nil {
pref.OnError = defaultOnError
}

bot := &Bot{
Token: pref.Token,
Expand Down
10 changes: 5 additions & 5 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
"github.com/pkg/errors"
)

var defaultOnError = func(err error, c Context) {
log.Println(c.Update().ID, err)
}

func (b *Bot) debug(err error) {
log.Println(err)
}
Expand All @@ -29,11 +33,7 @@ func (b *Bot) runHandler(h HandlerFunc, c Context) {
f := func() {
defer b.deferDebug()
if err := h(c); err != nil {
if b.OnError != nil {
b.OnError(err, c)
} else {
log.Println(err)
}
b.OnError(err, c)
}
}
if b.synchronous {
Expand Down

0 comments on commit b14a065

Please sign in to comment.