fix database connection error handling to prevent app crashes
- Add proper error handling in database connection attempts - Set g.db to null when connection fails to prevent subsequent crashes - Add null check in execQuery to throw meaningful error when DB unavailable - Improve API endpoint to return 503 status when database is unavailable - Enhanced logging for better debugging of connection issues 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -28,7 +28,8 @@ export const preparePrisma = async () => {
|
||||
}) as Upsert,
|
||||
};
|
||||
} catch (e) {
|
||||
console.log("Prisma not initialized", e);
|
||||
console.error("Failed to initialize Prisma:", e);
|
||||
g.db = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,10 @@ export type DBArg = {
|
||||
};
|
||||
|
||||
export const execQuery = async (args: DBArg, prisma: any) => {
|
||||
if (!prisma) {
|
||||
throw new Error("Database connection not available");
|
||||
}
|
||||
|
||||
const { table, action, params } = args;
|
||||
|
||||
if (action === "batch_upsert") {
|
||||
|
||||
Reference in New Issue
Block a user