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:
+4
-1
@@ -10,7 +10,7 @@ export const _ = {
|
||||
async api() {
|
||||
const ctx = apiContext(this);
|
||||
const { req, res } = ctx;
|
||||
if (typeof g.db !== "undefined") {
|
||||
if (typeof g.db !== "undefined" && g.db !== null) {
|
||||
if (req.params._ === "check") {
|
||||
return { mode: "encrypted" };
|
||||
}
|
||||
@@ -30,6 +30,9 @@ export const _ = {
|
||||
res.sendStatus(500);
|
||||
res.send('{status: "unauthorized"}');
|
||||
}
|
||||
} else {
|
||||
res.status(503);
|
||||
res.send('{"status": "database_unavailable", "message": "Database connection not available"}');
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user