fix(api): return 503 instead of 500 when Jellyfin/SSH not configured
On a fresh deploy with no Jellyfin service configured yet, get_jellyfin_client (and get_user_id / get_ssh_client) raised a plain RuntimeError, which bubbled up as a 500 traceback on every Jellyfin-dependent route (dashboard counts/libraries/activity, media, users). Convert those RuntimeErrors to HTTPException(503) with a clear detail message so FastAPI returns a clean 503 JSON response instead of a 500, and the frontend can render a not-configured state. - dependencies.py: get_jellyfin_client (no service / missing creds), get_user_id (no users discovered), and get_ssh_client (no SSH machine + no legacy key path) now raise HTTPException(503, detail=...). - tests/test_api.py: added TestDashboard.test_jellyfin_endpoints_return_503_when_not_configured covering /api/dashboard/counts and /activity. ruff clean; 240 backend tests pass.
This commit is contained in:
@@ -211,6 +211,22 @@ class TestDashboard:
|
||||
data = response.json()
|
||||
assert len(data) == 2
|
||||
|
||||
def test_jellyfin_endpoints_return_503_when_not_configured(self, test_client):
|
||||
# Remove the mocked Jellyfin dependency so the real one runs; with no
|
||||
# Jellyfin service seeded, endpoints must degrade to 503, not 500.
|
||||
app.dependency_overrides.pop(get_jellyfin_client, None)
|
||||
app.dependency_overrides.pop(get_user_id, None)
|
||||
try:
|
||||
for path in ("/api/dashboard/counts", "/api/dashboard/activity"):
|
||||
response = test_client.get(path)
|
||||
assert response.status_code == 503, path
|
||||
detail = response.json()["detail"]
|
||||
assert "configured" in detail, path
|
||||
finally:
|
||||
# Restore the mocks for subsequent tests in this fixture session.
|
||||
app.dependency_overrides[get_jellyfin_client] = lambda: MagicMock()
|
||||
app.dependency_overrides[get_user_id] = lambda: "user123"
|
||||
|
||||
|
||||
# --- Settings reset ---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user