Log ban errors and handle exceptions

This commit is contained in:
Leppunen 2020-12-22 11:23:52 +02:00
parent 2aa7f651cb
commit 56bb0d47a2
1 changed files with 14 additions and 1 deletions

View File

@ -1,5 +1,5 @@
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 WS = require('ws');
const Config = require('./config.json');
@ -143,6 +143,9 @@ pnslWebSocket.on('message', async (data) => {
});
clients[i].on('error', (error) => {
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 (clients[i].ready) {
return;
@ -206,3 +209,13 @@ pnslWebSocket.on('message', async (data) => {
}
}, 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);
});