feat: Implement custom error classes, a Drizzle transaction utility, and update Discord.js ephemeral message flags.
This commit is contained in:
15
src/lib/db.ts
Normal file
15
src/lib/db.ts
Normal 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
18
src/lib/errors.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user