From 6e2a728e76a11c92ddf955f7a93f4ef16be8119e Mon Sep 17 00:00:00 2001 From: Laurynas Karvelis Date: Fri, 16 Feb 2018 02:26:06 +0200 Subject: [PATCH] Recover from http error with telegram server and carry on fetching updates --- src/functions/poll.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/functions/poll.js b/src/functions/poll.js index eb71b03..27b640f 100644 --- a/src/functions/poll.js +++ b/src/functions/poll.js @@ -1,13 +1,17 @@ export default function poll(bot) { - return bot.api.getUpdates(bot.update).then(response => { - if (!response.result.length) { - return poll(bot); - } - bot.emit('update', response.result); + return bot.api.getUpdates(bot.update) + .then(response => { + if (!response.result.length) { + return poll(bot); + } + bot.emit('update', response.result); - if (bot._stop) { - return null; - } - return poll(bot); - }); + if (bot._stop) { + return null; + } + return poll(bot); + }) + .catch(() => { + return poll(bot); + }); }