devsnek / discord-rich-presence

Discord RPC but only the rich presence part
122 stars 16 forks source link

Closing Discord, unhandled promise rejection #30

Closed xL0b0 closed 3 weeks ago

xL0b0 commented 3 years ago

If closing Discord, this ends up in an unhandled promise rejection. Could this please be changed so it could be handled, in order to retry initializing it after it was closed?

Sv443 commented 3 years ago

Try listening for the error event like this:

const client = require('discord-rich-presence')('180984871685062656');

client.on('error', err => {
    console.log(`Error: ${err}`);
});
ozaik commented 3 years ago

Try listening for the error event like this:

const client = require('discord-rich-presence')('180984871685062656');

client.on('error', err => {
    console.log(`Error: ${err}`);
});

We can't handle error with this. The code stop running after that

xL0b0 commented 3 years ago

This can only account for errors in the init. Otherwise you will still get

(node:16829) UnhandledPromiseRejectionWarning: Error: connection closed

if you close Discord while running.