fix: correction des incohérance avec la base de donnée

This commit is contained in:
Puechberty Arthur
2026-04-12 12:00:48 +02:00
parent e2bcb92e15
commit 8cd46fea76
3 changed files with 18 additions and 11 deletions
+5 -1
View File
@@ -8,7 +8,11 @@ loadEnv();
const envSchema = z.object({
DISCORD_TOKEN: z.string().min(1, "DISCORD_TOKEN is required"),
DISCORD_CLIENT_ID: z.string().min(1, "DISCORD_CLIENT_ID is required"),
DATABASE_URL: z.string().optional().transform((value) => value && value.length > 0 ? value : undefined),
DATABASE_URL: z
.string()
.trim()
.min(1, "DATABASE_URL is required")
.url("DATABASE_URL must be a valid URL"),
DATABASE_SSL: z
.string()
.optional()
+7 -4
View File
@@ -165,19 +165,22 @@ export const initPresenceStore = async (): Promise<PresenceStore> => {
return store;
}
if (!env.DATABASE_URL) {
throw new Error("DATABASE_URL is required to initialize PostgreSQL presence storage.");
}
const pool = new Pool({
connectionString: env.DATABASE_URL,
ssl: env.DATABASE_SSL ? { rejectUnauthorized: false } : undefined,
});
const nextStore = new PresenceStore(pool);
try {
await nextStore.init();
store = nextStore;
return nextStore;
} catch (error) {
await pool.end().catch(() => {
// Ignore close errors; the original init error is the one we want to surface.
});
throw error;
}
};
export const getPresenceStore = (): PresenceStore => {
+3 -3
View File
@@ -94,10 +94,10 @@ const bootstrap = async (): Promise<void> => {
await client.login(env.DISCORD_TOKEN);
};
bootstrap().catch((error) => {
bootstrap().catch(async (error) => {
console.error("[boot] fatal error", error);
void shutdownPresenceStore().catch((closeError) => {
await shutdownPresenceStore().catch((closeError) => {
console.error("[boot] failed to close presence store", closeError);
});
process.exitCode = 1;
process.exit(1);
});