Skip to content

Commit

Permalink
feat: updated error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
e-enes committed Apr 13, 2024
1 parent 2e8b050 commit 66c219e
Showing 1 changed file with 39 additions and 25 deletions.
64 changes: 39 additions & 25 deletions src/utils/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

0 comments on commit 66c219e

Please sign in to comment.