feat: Implement custom error classes, a Drizzle transaction utility, and update Discord.js ephemeral message flags.

This commit is contained in:
syntaxbullet
2025-12-15 22:14:17 +01:00
parent 3c81fd8396
commit 7e986fae5a
14 changed files with 112 additions and 114 deletions

15
src/lib/db.ts Normal file
View File

@@ -0,0 +1,15 @@
import { DrizzleClient } from "./DrizzleClient";
import type { Transaction } from "./types";
export const withTransaction = async <T>(
callback: (tx: Transaction) => Promise<T>,
tx?: Transaction
): Promise<T> => {
if (tx) {
return await callback(tx);
} else {
return await DrizzleClient.transaction(async (newTx) => {
return await callback(newTx);
});
}
};

18
src/lib/errors.ts Normal file
View File

@@ -0,0 +1,18 @@
export class ApplicationError extends Error {
constructor(message: string) {
super(message);
this.name = this.constructor.name;
}
}
export class UserError extends ApplicationError {
constructor(message: string) {
super(message);
}
}
export class SystemError extends ApplicationError {
constructor(message: string) {
super(message);
}
}

View File

@@ -11,3 +11,8 @@ export interface Event<K extends keyof ClientEvents> {
once?: boolean;
execute: (...args: ClientEvents[K]) => Promise<void> | void;
}
import { DrizzleClient } from "./DrizzleClient";
export type DbClient = typeof DrizzleClient;
export type Transaction = Parameters<Parameters<DbClient['transaction']>[0]>[0];