Emit bot errors inside inner catch promise chain handlers

This commit is contained in:
Laurynas Karvelis 2018-02-18 12:40:21 +02:00
parent 6e2a728e76
commit a404e2ee82
2 changed files with 20 additions and 10 deletions

View File

@ -11,7 +11,8 @@ export default function poll(bot) {
} }
return poll(bot); return poll(bot);
}) })
.catch(() => { .catch(e => {
bot.emit('error', e);
return poll(bot); 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;
});
} }
/** /**