From c1d40eb1be7771c59af99dac2b56ec26aa22184c Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Thu, 10 Nov 2022 01:34:02 -0700 Subject: [PATCH] abstract errorhandle --- bot.js | 5 ++--- src/util/log/errorhandler.js | 8 ++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 src/util/log/errorhandler.js diff --git a/bot.js b/bot.js index ab0488a..672c6b3 100644 --- a/bot.js +++ b/bot.js @@ -3,6 +3,7 @@ const Discord = require('discord.js'); const auth = require('./src/json/auth.json'); const config = require('./src/json/config.json'); const randresp = require('./src/json/randresp.json'); +const errorhandler = require('./src/util/log/errorhandler'); const log = require('./src/util/log/log'); @@ -27,9 +28,7 @@ const startBot = async () => { await require('./src/handle/startup/run/login')(client); //log in to discord await require('./src/db/connect')(client); //connect to database }; -startBot().catch(() => { - console.log("\nWell this is awkward.\n"); -}); // TODO add a .catch() and flag to recover the process +startBot().catch(e => errorhandler(e)); // TODO add a .catch() and flag to recover the process // feels like there isn't a function name to do this justice :joy: // to do list: diff --git a/src/util/log/errorhandler.js b/src/util/log/errorhandler.js new file mode 100644 index 0000000..56e5ddc --- /dev/null +++ b/src/util/log/errorhandler.js @@ -0,0 +1,8 @@ +const chalk = require('chalk'); + +module.exports = e => { + console.log(`#######################################\n\n${chalk.grey('[NATS]')} >> ${chalk.hex('#78d9f8')("Well this is awkward.")}\n`); + console.log(`${chalk.bold.redBright.underline("There was an error that killed Natsuki's process.")}\n${chalk.redBright("See available stack trace and error information below.")}\n`); + console.error(e); + console.log(`\n#######################################\n\n${chalk.grey('[NATS]')} >> ${chalk.hex('#78d9f8')("Back to sleepies...")}`); +}; \ No newline at end of file