-
-
Notifications
You must be signed in to change notification settings - Fork 16
Viewer shows generic 'Unexpected error' when database is unreachable #92
Description
Problem
When PostgreSQL is down or unreachable, the viewer login endpoint returns a generic 500 "Internal server error" which the frontend displays as "Unexpected error, please try again". This gives no indication that the database is the problem.
The root cause is that db.get_viewer_by_username() at main.py:769 (and similar DB calls throughout the login flow) have no connection error handling. When the DB connection fails, the unhandled asyncpg/aiosqlite exception propagates up as a 500.
Expected Behavior
- Login should return
503 Service Unavailablewith a clear message like "Database temporarily unavailable" - The master account (env var credentials) should still work even when the DB is down (fall through to env var check)
- The frontend should display a user-friendly message distinguishing DB issues from auth failures
Affected Endpoints
The login() function is the most visible, but all endpoints that hit the DB without catching connection errors are affected:
POST /api/login— viewer account lookup failsPOST /auth/token— token lookup failsGET /api/auth/check— session restore fails (already has a warning log but no user-facing message)- All admin CRUD endpoints
Context
Discovered when PostgreSQL containers on Unraid were in "Created" state after a kernel panic. The viewers were running but couldn't reach postgres, causing all login attempts to fail with unhelpful errors.
Suggested Fix
- Catch DB connection errors in
login()and fall through to master credential check - Return 503 with specific message for DB-dependent operations when connection fails
- Add a health check endpoint (
/api/health) that reports DB connectivity status