Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Error handling #10

Closed
twinone opened this issue Apr 20, 2017 · 1 comment
Closed

Question: Error handling #10

twinone opened this issue Apr 20, 2017 · 1 comment

Comments

@twinone
Copy link

twinone commented Apr 20, 2017

I've been searching through the docs but I can only find something like "all errors are emitted on the bot object".

How can I catch them?
Maybe it's an idea to write a very small sample of error catching so that the process doesn't crash when a network error occurs.

Thanks!

@mildsunrise
Copy link
Member

Yes, errors are emitted as error events on the bot object; you can get them by listening to those events:

bot.on("error", (err) => {
  // TODO
});

If you don't register any listeners, Node.JS exits when an error event is emitted.

If you want to catch errors when sending a message, you can do so with the then() method (in which case the event is not emitted at all).

PS: Network errors when retrieving updates are emitted as updateError instead since they're retried.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants