From f718518358895ec3a8d9a423dd82c4ae6d01d29f Mon Sep 17 00:00:00 2001 From: Lamp Date: Tue, 11 Sep 2018 19:41:16 -0700 Subject: [PATCH] Differentiate errors Uncaught exceptions mess things up --- src/main.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main.js b/src/main.js index 1e0c5a7..8e63a9f 100755 --- a/src/main.js +++ b/src/main.js @@ -9,17 +9,17 @@ global.dClient = new Discord.Client({ disableEveryone: true }); // error handling { let webhook = new Discord.WebhookClient(config.webhooks.error[0], config.webhooks.error[1]); - global.onError = function logError(error) { + global.onError = function logError(error, title) { let msg = error && (error.stack || error.message || error); - console.error(msg); + console.error(title + ':\n', msg); try { - webhook.send(`\`\`\`\n${msg}\n\`\`\``).catch(()=>{}); + webhook.send(`${title ? `**${title}:**` : ""}\`\`\`\n${msg}\n\`\`\``).catch(()=>{}); } catch(e) {} } - process.on('unhandledRejection', onError); - process.on('uncaughtException', onError); - dClient.on('error', onError); - dClient.on('warn', onError); + process.on('unhandledRejection', error => onError(error, "Unhandled Rejection"); + process.on('uncaughtException', error => onError(error, "Uncaught Exception")); + dClient.on('error', error => onError(error, "Discord Client Error")); + dClient.on('warn', error => onError(error, "Discord Client Warning")); }