mirror of
https://github.com/arthur-pbty/flint.git
synced 2026-08-01 20:29:03 +02:00
fix: correction des incohérance avec la base de donnée
This commit is contained in:
@@ -8,7 +8,11 @@ loadEnv();
|
|||||||
const envSchema = z.object({
|
const envSchema = z.object({
|
||||||
DISCORD_TOKEN: z.string().min(1, "DISCORD_TOKEN is required"),
|
DISCORD_TOKEN: z.string().min(1, "DISCORD_TOKEN is required"),
|
||||||
DISCORD_CLIENT_ID: z.string().min(1, "DISCORD_CLIENT_ID 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
|
DATABASE_SSL: z
|
||||||
.string()
|
.string()
|
||||||
.optional()
|
.optional()
|
||||||
|
|||||||
@@ -165,19 +165,22 @@ export const initPresenceStore = async (): Promise<PresenceStore> => {
|
|||||||
return store;
|
return store;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!env.DATABASE_URL) {
|
|
||||||
throw new Error("DATABASE_URL is required to initialize PostgreSQL presence storage.");
|
|
||||||
}
|
|
||||||
|
|
||||||
const pool = new Pool({
|
const pool = new Pool({
|
||||||
connectionString: env.DATABASE_URL,
|
connectionString: env.DATABASE_URL,
|
||||||
ssl: env.DATABASE_SSL ? { rejectUnauthorized: false } : undefined,
|
ssl: env.DATABASE_SSL ? { rejectUnauthorized: false } : undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
const nextStore = new PresenceStore(pool);
|
const nextStore = new PresenceStore(pool);
|
||||||
await nextStore.init();
|
try {
|
||||||
store = nextStore;
|
await nextStore.init();
|
||||||
return nextStore;
|
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 => {
|
export const getPresenceStore = (): PresenceStore => {
|
||||||
|
|||||||
+3
-3
@@ -94,10 +94,10 @@ const bootstrap = async (): Promise<void> => {
|
|||||||
await client.login(env.DISCORD_TOKEN);
|
await client.login(env.DISCORD_TOKEN);
|
||||||
};
|
};
|
||||||
|
|
||||||
bootstrap().catch((error) => {
|
bootstrap().catch(async (error) => {
|
||||||
console.error("[boot] fatal error", error);
|
console.error("[boot] fatal error", error);
|
||||||
void shutdownPresenceStore().catch((closeError) => {
|
await shutdownPresenceStore().catch((closeError) => {
|
||||||
console.error("[boot] failed to close presence store", closeError);
|
console.error("[boot] failed to close presence store", closeError);
|
||||||
});
|
});
|
||||||
process.exitCode = 1;
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user