diff --git a/src/utils/error.ts b/src/utils/error.ts index 572acd6..f4b2721 100644 --- a/src/utils/error.ts +++ b/src/utils/error.ts @@ -11,31 +11,45 @@ if (webhookId && webhookToken) { webhookClient = new WebhookClient({ id: webhookId, token: webhookToken }); } -process.on("uncaughtException", (error) => { - webhookClient - .send({ - embeds: [ - new EmbedBuilder() - .setTitle("Uncaught Exception") - .setDescription( - `**Message:** ${error?.message}\n\n**Name:** ${error?.name}\n**Cause:** ${error?.cause}\n**Source:** ${String(error?.cause)}\n\n**Stack:**\n\`${error?.stack}\`` - ) - .setColor(config.message.colors.error), - ], - }) - ?.catch(() => { - console.error(error); - process.exit(1); - }); +process.on("uncaughtException", async (error) => { + if (webhookClient) { + await webhookClient + .send({ + embeds: [ + new EmbedBuilder() + .setTitle("Uncaught Exception") + .setDescription( + `**Message:** ${error?.message}\n\n**Name:** ${error?.name}\n**Cause:** ${error?.cause}\n**Source:** ${String(error?.cause)}\n\n**Stack:**\n\`${error?.stack}\`` + ) + .setColor(config.message.colors.error), + ], + }) + .catch((e) => { + console.error("Webhook Error", e); + process.exit(1); + }); + + return; + } + + console.error(error); + process.exit(1); }); -process.on("unhandledRejection", (reason) => { - webhookClient - .send({ - embeds: [new EmbedBuilder().setTitle("Uncaught Rejection").setDescription(String(reason)).setColor(config.message.colors.error)], - }) - .catch(() => { - console.error(reason); - process.exit(1); - }); +process.on("unhandledRejection", async (reason) => { + if (webhookClient) { + await webhookClient + .send({ + embeds: [new EmbedBuilder().setTitle("Uncaught Rejection").setDescription(String(reason)).setColor(config.message.colors.error)], + }) + .catch((e) => { + console.error("Webhook Error", e); + process.exit(1); + }); + + return; + } + + console.error(reason); + process.exit(1); });