Skip to content

fix: return 503 when database is unreachable instead of generic 500#93

Merged
GeiserX merged 2 commits intomainfrom
ai/db-error-handling
Mar 13, 2026
Merged

fix: return 503 when database is unreachable instead of generic 500#93
GeiserX merged 2 commits intomainfrom
ai/db-error-handling

Conversation

@GeiserX
Copy link
Owner

@GeiserX GeiserX commented Mar 13, 2026

Summary

  • Login: Wraps DB viewer lookup in try/except, falling through to master env var credentials when DB is down. Returns 503 only when the failed login cannot be resolved without the database.
  • Audit logs: All audit log writes in the login flow are now wrapped in try/except so they never crash the response.
  • Data endpoints: All 13 existing catch-all handlers now return HTTP 503 "Database temporarily unavailable" for connection errors (OSError in the exception chain), keeping 500 for non-connection bugs.
  • Global exception handler: Catches unhandled DB connection errors from admin endpoints and any other uncovered paths.
  • Health endpoint: GET /api/health returns DB connectivity status (200 ok / 503 degraded).

Closes #92

Test plan

  • All 26 auth tests pass
  • All 77 non-import tests pass (import test fails due to pre-existing missing bs4 dependency)
  • Manual: stop postgres container, verify login shows "Database temporarily unavailable" instead of "Unexpected error"
  • Manual: stop postgres, verify master env var login still works
  • Manual: verify /api/health returns {"status": "degraded", "database": "unreachable"} with 503

🤖 Generated with Claude Code

GeiserX and others added 2 commits March 13, 2026 18:23
- Login: wrap DB viewer lookup in try/except, fall through to master
  env var credentials when DB is down. Return 503 only if the failed
  login cannot be resolved without the database.
- Audit log writes: wrap in try/except so they never crash the login flow.
- Data endpoints: all 13 existing catch-all handlers now return 503
  "Database temporarily unavailable" for connection errors (OSError in
  the exception chain), keeping 500 for non-connection errors.
- Global exception handler: catches unhandled DB connection errors from
  admin endpoints and any other uncovered paths.
- Health endpoint: GET /api/health returns DB connectivity status (200/503).

Closes #92

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@GeiserX GeiserX merged commit e19f89a into main Mar 13, 2026
6 checks passed
@github-actions
Copy link

🐳 Dev images published!

  • drumsergio/telegram-archive:dev
  • drumsergio/telegram-archive-viewer:dev

The dev/test instance will pick up these changes automatically (Portainer GitOps).

To test locally:

docker pull drumsergio/telegram-archive:dev
docker pull drumsergio/telegram-archive-viewer:dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Viewer shows generic 'Unexpected error' when database is unreachable

1 participant