From 56bb0d47a27560c2246719b3199eb117a5a077e2 Mon Sep 17 00:00:00 2001 From: Leppunen Date: Tue, 22 Dec 2020 11:23:52 +0200 Subject: [PATCH] Log ban errors and handle exceptions --- index.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 88d3adf..0975185 100644 --- a/index.js +++ b/index.js @@ -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); + }); \ No newline at end of file