From 2371404f1c67b37ae41c124b32dcb2ca9008ae66 Mon Sep 17 00:00:00 2001 From: Mahdi Dibaiee Date: Mon, 5 Feb 2018 21:46:29 +0330 Subject: [PATCH 1/4] chore: bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 255895b..5746467 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "telegram-api", - "version": "0.9.1", + "version": "1.0.0", "description": "Control Telegram bots easily using the new Telegram API", "main": "build/index.js", "scripts": { -- 2.34.1 From 9d2c4be69aea63ee66399fe994eed6c6a088f348 Mon Sep 17 00:00:00 2001 From: Mahdi Dibaiee Date: Wed, 14 Feb 2018 14:09:25 +0330 Subject: [PATCH 2/4] chore: bump version to 1.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5746467..bc265bb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "telegram-api", - "version": "1.0.0", + "version": "1.0.1", "description": "Control Telegram bots easily using the new Telegram API", "main": "build/index.js", "scripts": { -- 2.34.1 From 6e2a728e76a11c92ddf955f7a93f4ef16be8119e Mon Sep 17 00:00:00 2001 From: Laurynas Karvelis Date: Fri, 16 Feb 2018 02:26:06 +0200 Subject: [PATCH 3/4] 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); + }); } -- 2.34.1 From a404e2ee827236ccbeafbae3821fd5c9920f3929 Mon Sep 17 00:00:00 2001 From: Laurynas Karvelis Date: Sun, 18 Feb 2018 12:40:21 +0200 Subject: [PATCH 4/4] Emit bot errors inside inner catch promise chain handlers --- src/functions/poll.js | 3 ++- src/index.js | 27 ++++++++++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/functions/poll.js b/src/functions/poll.js index 27b640f..089131a 100644 --- a/src/functions/poll.js +++ b/src/functions/poll.js @@ -11,7 +11,8 @@ export default function poll(bot) { } return poll(bot); }) - .catch(() => { + .catch(e => { + bot.emit('error', e); return poll(bot); }); } diff --git a/src/index.js b/src/index.js index 2710b06..445124c 100644 --- a/src/index.js +++ b/src/index.js @@ -75,17 +75,22 @@ export default class Bot extends EventEmitter { if (hook) { return webhook(hook, this); } - return this.api.getMe().then(response => { - this.info = response.result; + return this.api.getMe() + .then(response => { + this.info = response.result; - this.on('update', this._update); + this.on('update', this._update); - if (hook) { - return webhook(hook, this); - } + if (hook) { + return webhook(hook, this); + } - return poll(this); - }); + return poll(this); + }) + .catch(e => { + this.emit('error', e); + throw e; + }); } /** @@ -138,7 +143,11 @@ export default class Bot extends EventEmitter { * @return {unknown} returns the result of calling message's send method */ send(message) { - return message.send(this); + return message.send(this) + .catch(e => { + this.emit('error', e); + throw e; + }); } /** -- 2.34.1