From 6d3659f84fea49f791af4e1dd4db983d39982ae4 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Wed, 18 Dec 2024 13:13:09 -0700 Subject: [PATCH] Descriptive error messages --- index.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index ba38970..19a4eb8 100644 --- a/index.js +++ b/index.js @@ -794,11 +794,11 @@ dcClient.on("guildMemberRemove", (member) => { deleteExtension(result.result.fetchExtension.user.extension).then((delResult) => { sendLog(`${colors.cyan("[INFO]")} Deleted extension ${result.result.fetchExtension.user.extension} because the user left the server`); }).catch((error) => { - sendLog(`${colors.red("[ERROR]")} ${error}`); + sendLog(`${colors.red("[ERROR]")} Error deleting ext ${error}`); }); } }).catch((error) => { - sendLog(`${colors.red("[ERROR]")} ${error}`); + sendLog(`${colors.red("[ERROR]")} Error looking up extension to delete ${error}`); }); }); @@ -890,7 +890,7 @@ dcClient.on('interactionCreate', async interaction => { } }).catch((error) => { // The user doesn't have an extension, create one - sendLog(`${colors.red("[ERROR]")} ${error}`) + sendLog(`${colors.red("[ERROR]")} Error looking up extension ${error}`) interaction.editReply({ content: "You don't have an extension!", ephemeral: true @@ -1054,7 +1054,7 @@ dcClient.on('interactionCreate', async interaction => { }); }).catch((error) => { interaction.editReply(`Error adding you to the paging group: ${error}`); - sendLog(`${colors.red("[ERROR]")} ${error}`); + sendLog(`${colors.red("[ERROR]")} Error adding user to pg group ${error}`); }); } else { // They're already in the group, return an ephemeral message saying so @@ -1065,7 +1065,7 @@ dcClient.on('interactionCreate', async interaction => { } }).catch((error) => { interaction.editReply(`Error adding you to the paging group: ${error}`); - sendLog(`${colors.red("[ERROR]")} ${error}`); + sendLog(`${colors.red("[ERROR]")} Error looking up user in pg group ${error}`); }); break; case "remove": @@ -1089,12 +1089,12 @@ dcClient.on('interactionCreate', async interaction => { }); }).catch((error) => { interaction.editReply(`Error removing you from the paging group: ${error}`); - sendLog(`${colors.red("[ERROR]")} ${error}`); + sendLog(`${colors.red("[ERROR]")} Error while removing user from page group ${error}`); }); } }).catch((error) => { interaction.editReply(`Error removing you from the paging group: ${error}`); - sendLog(`${colors.red("[ERROR]")} ${error}`); + sendLog(`${colors.red("[ERROR]")} Error while looking if user is in pg grp ${error}`); }); break; } @@ -1120,7 +1120,7 @@ dcClient.on('interactionCreate', async interaction => { content: `Error killing calls: ${err}`, ephemeral: true }); - sendLog(`${colors.red("[ERROR]")} ${err}`); + sendLog(`${colors.red("[ERROR]")} Error killing calls ${err}`); } stream.on("exit", (code) => { interaction.reply({ @@ -1139,13 +1139,13 @@ dcClient.on('interactionCreate', async interaction => { sshConn.exec("fwconsole reload", (err, stream) => { if (err) { interaction.editReply(`Error reloading FreePBX: ${err}`); - sendLog(`${colors.red("[ERROR]")} ${err}`); + sendLog(`${colors.red("[ERROR]")} Error manually reloading fwconsole ${err}`); } stream.on('exit', (code, signal) => { sshConn.exec("asterisk -x 'core reload'", (err, stream) => { if (err) { interaction.editReply(`Error reloading Asterisk: ${err}`); - sendLog(`${colors.red("[ERROR]")} ${err}`); + sendLog(`${colors.red("[ERROR]")} Error manually reloading asterisk ${err}`); } stream.on('exit', (code, signal) => { interaction.editReply("Reloaded FreePBX and Asterisk!"); @@ -1162,7 +1162,7 @@ dcClient.on('interactionCreate', async interaction => { sshConn.exec("reboot", (err, stream) => { if (err) { interaction.editReply(`Error rebooting server: ${err}`); - sendLog(`${colors.red("[ERROR]")} ${err}`); + sendLog(`${colors.red("[ERROR]")} Error rebooting? ${err}`); } stream.on('exit', (code, signal) => { interaction.editReply("Rebooting server...\nThe bot will now disconnect and restart in 1 minute. Please stand by...").then(() => { @@ -1203,7 +1203,7 @@ dcClient.on('interactionCreate', async interaction => { sshConn.exec(`fwconsole ${cmd}`, (err, stream) => { if (err) { interaction.editReply(`Error running command: ${err}`); - sendLog(`${colors.red("[ERROR]")} ${err}`); + sendLog(`${colors.red("[ERROR]")} Error running fwconsole command ${err}`); } outputStream = "" stream.on("data", (data) => { @@ -1256,7 +1256,7 @@ dcClient.on('interactionCreate', async interaction => { sshConn.exec(`asterisk -x '${cmd2}'`, (err, stream) => { if (err) { interaction.editReply(`Error running command: ${err}`); - sendLog(`${colors.red("[ERROR]")} ${err}`); + sendLog(`${colors.red("[ERROR]")} Error running asterisk cli command ${err}`); } outputStream = "" stream.on("data", (data) => { @@ -1293,7 +1293,7 @@ dcClient.on('interactionCreate', async interaction => { sshConn.exec(cmd3, (err, stream) => { if (err) { interaction.editReply(`Error running command: ${err}`); - sendLog(`${colors.red("[ERROR]")} ${err}`); + sendLog(`${colors.red("[ERROR]")} Error running shell command ${err}`); } // if timeout is set, set a timeout before //timeout = setTimeout(() => { @@ -1525,7 +1525,7 @@ dcClient.on('interactionCreate', async interaction => { } }).catch((error) => { // The user doesn't have an extension, create one - sendLog(`${colors.red("[ERROR]")} ${error}`) + sendLog(`${colors.red("[ERROR]")} Error finding extension for user? ${error}`) interaction.editReply({ content: "You don't have an extension!", ephemeral: true @@ -1551,7 +1551,7 @@ dcClient.on('interactionCreate', async interaction => { } }).catch((error) => { // The user doesn't have an extension, create one - sendLog(`${colors.red("[ERROR]")} ${error}`) + sendLog(`${colors.red("[ERROR]")} User has not ext (lookup) ${error}`) interaction.editReply({ content: "That user doesn't have an extension!", ephemeral: true @@ -1664,7 +1664,7 @@ dcClient.on('interactionCreate', async interaction => { // Lets actually handle exceptions now process.on('unhandledRejection', (error) => { // Log a full error with line number - sendLog(`${colors.red("[ERROR]")} ${JSON.stringify(error)}`); + sendLog(`${colors.red("[ERROR]")} Unhandled Rejection ${error}`); // If config.ntfyUrl is set, Send the exception to ntfy if (config.ntfyUrl) fetch(config.ntfyUrl, { method: 'POST', // PUT works too @@ -1679,7 +1679,7 @@ process.on('unhandledRejection', (error) => { process.on('uncaughtException', (error) => { // Log a full error with line number - sendLog(`${colors.red("[ERROR]")} ${error.stack}`); + sendLog(`${colors.red("[ERROR]")} Uncaught Exception ${error.stack}`); // If config.ntfyUrl is set, Send the exception to ntfy if (config.ntfyUrl) fetch(config.ntfyUrl, { method: 'POST', // PUT works too