From f6cf1bb7824bd6bdb3f30e7932c10f653d5e27b1 Mon Sep 17 00:00:00 2001 From: Jqs7 <7@jqs7.com> Date: Tue, 30 Jun 2015 00:04:48 +0800 Subject: [PATCH 1/3] should not panic in production env --- updates.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/updates.go b/updates.go index 7106201..0fb2e50 100644 --- a/updates.go +++ b/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,15 +13,22 @@ func (bot *BotAPI) UpdatesChan(config UpdateConfig) (chan Update, error) { 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("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 + } } } + } }() From 69bb4a9c33b1861e616862688e1d60ffeb7d0c83 Mon Sep 17 00:00:00 2001 From: Jqs7 <7@jqs7.com> Date: Tue, 30 Jun 2015 11:28:55 +0800 Subject: [PATCH 2/3] update log message --- updates.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/updates.go b/updates.go index 0fb2e50..1a3a34a 100644 --- a/updates.go +++ b/updates.go @@ -17,7 +17,7 @@ func (bot *BotAPI) UpdatesChan(config UpdateConfig) (chan Update, error) { panic(err) } else { log.Println(err) - log.Println("Retry in 3 Seconds") + log.Println("Fail to GetUpdates,Retry in 3 Seconds...") time.Sleep(time.Second * 3) } } else { From 92ad19733ba69ebe635916af04cf51ea6fd4a71b Mon Sep 17 00:00:00 2001 From: Jqs7 <7@jqs7.com> Date: Tue, 30 Jun 2015 11:33:26 +0800 Subject: [PATCH 3/3] remove blank line --- updates.go | 1 - 1 file changed, 1 deletion(-) diff --git a/updates.go b/updates.go index 1a3a34a..edbcb20 100644 --- a/updates.go +++ b/updates.go @@ -28,7 +28,6 @@ func (bot *BotAPI) UpdatesChan(config UpdateConfig) (chan Update, error) { } } } - } }()