Log ban errors and handle exceptions

This commit is contained in:
Leppunen 2020-12-22 11:23:52 +02:00
parent 2aa7f651cb
commit 56bb0d47a2

View file

@ -1,5 +1,5 @@
const {extend: createGotClient} = require('got'); const {extend: createGotClient} = require('got');
const {ConnectionError, SayError, TimeoutError, ChatClient} = require('dank-twitch-irc'); const {ConnectionError, SayError, TimeoutError, UserBanError, ChatClient} = require('dank-twitch-irc');
const chalk = require('chalk'); const chalk = require('chalk');
const WS = require('ws'); const WS = require('ws');
const Config = require('./config.json'); const Config = require('./config.json');
@ -143,6 +143,9 @@ pnslWebSocket.on('message', async (data) => {
}); });
clients[i].on('error', (error) => { clients[i].on('error', (error) => {
if (error instanceof SayError) return; if (error instanceof SayError) return;
if (error instanceof UserBanError) {
return console.warn(`Failed to ban user ${error.username} from ${error.channelname}`);
}
if (error instanceof ConnectionError) { if (error instanceof ConnectionError) {
if (clients[i].ready) { if (clients[i].ready) {
return; return;
@ -206,3 +209,13 @@ pnslWebSocket.on('message', async (data) => {
} }
}, pingInterval); }, pingInterval);
})(); })();
process
.on('unhandledRejection', (err) => {
if (err.name === 'SayError') return
console.error(`${chalk.red('[UnhandledRejection]')} || [${err.name}] ${err} - ${err.stack}`);
})
.on('uncaughtException', (err) => {
console.error(`${chalk.red('[UncaughtException]')} || ${err.message}`);
process.exit(0);
});