Merge pull request #2 from jqs7/master should not panic in production env
Syfaro syfaro@foxpaw.in
Mon, 29 Jun 2015 22:36:37 -0500
1 files changed,
18 insertions(+),
7 deletions(-)
jump to
M
updates.go
→
updates.go
@@ -1,5 +1,10 @@
package tgbotapi +import ( + "log" + "time" +) + // UpdatesChan returns a chan that is called whenever a new message is gotten. func (bot *BotAPI) UpdatesChan(config UpdateConfig) (chan Update, error) { bot.Updates = make(chan Update, 100)@@ -8,13 +13,19 @@ go func() {
for { updates, err := bot.GetUpdates(config) if err != nil { - panic(err) - } - - for _, update := range updates { - if update.UpdateID >= config.Offset { - config.Offset = update.UpdateID + 1 - bot.Updates <- update + if bot.Debug == true { + panic(err) + } else { + log.Println(err) + log.Println("Fail to GetUpdates,Retry in 3 Seconds...") + time.Sleep(time.Second * 3) + } + } else { + for _, update := range updates { + if update.UpdateID >= config.Offset { + config.Offset = update.UpdateID + 1 + bot.Updates <- update + } } } }