Skip to content

Commit 730ce6f

Browse files
committed
Very basic error handling
1 parent 7bc6e64 commit 730ce6f

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/baseBot.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as fs from "fs";
1111
import { Sequelize } from "sequelize";
1212
import {Listeners} from "./interfaces/Listeners";
1313
import path from "path";
14+
import {errorHandler} from "./utility/ErrorHandling";
1415

1516
const client = new AllyClient({
1617
intents: config.intents as GatewayIntentBits[],
@@ -79,6 +80,13 @@ client.on("interactionCreate", (interaction: Interaction) => {
7980
if (buttonFollowUp) buttonFollowUp.followup(client, interaction);
8081
});
8182

83+
process.on("uncaughtException", (error) => {
84+
console.error(error);
85+
86+
if (!errorHandler.isTrustedError(error)) {
87+
process.exit(1);
88+
}
89+
});
8290

8391
client.login(config.token);
8492

src/utility/ErrorHandling.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {DiscordAPIError, DiscordjsError} from "discord.js";
2+
3+
class ErrorHandling {
4+
public isTrustedError(err: Error) {
5+
return err instanceof DiscordAPIError || err instanceof DiscordjsError;
6+
}
7+
}
8+
9+
export const errorHandler = new ErrorHandling();

0 commit comments

Comments
 (0)