Merge pull request #40 from laurynas-karvelis/master

Don't merge yet: Keep on listening to Telegram's updates even if requests with telegram server fail
This commit is contained in:
Mahdi Dibaiee 2018-02-18 20:51:06 +03:30 committed by GitHub
commit 6831c35f61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 19 deletions

View File

@ -1,5 +1,6 @@
export default function poll(bot) { export default function poll(bot) {
return bot.api.getUpdates(bot.update).then(response => { return bot.api.getUpdates(bot.update)
.then(response => {
if (!response.result.length) { if (!response.result.length) {
return poll(bot); return poll(bot);
} }
@ -9,5 +10,9 @@ export default function poll(bot) {
return null; return null;
} }
return poll(bot); return poll(bot);
})
.catch(e => {
bot.emit('error', e);
return poll(bot);
}); });
} }

View File

@ -75,7 +75,8 @@ export default class Bot extends EventEmitter {
if (hook) { if (hook) {
return webhook(hook, this); return webhook(hook, this);
} }
return this.api.getMe().then(response => { return this.api.getMe()
.then(response => {
this.info = response.result; this.info = response.result;
this.on('update', this._update); this.on('update', this._update);
@ -85,6 +86,10 @@ export default class Bot extends EventEmitter {
} }
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 * @return {unknown} returns the result of calling message's send method
*/ */
send(message) { send(message) {
return message.send(this); return message.send(this)
.catch(e => {
this.emit('error', e);
throw e;
});
} }
/** /**