Recover from http error with telegram server and carry on fetching updates

This commit is contained in:
Laurynas Karvelis 2018-02-16 02:26:06 +02:00
parent 790f988148
commit 6e2a728e76

View File

@ -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);
});
}