diff --git a/app/main.py b/app/main.py index d6f528c..0742360 100644 --- a/app/main.py +++ b/app/main.py @@ -152,10 +152,10 @@ body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;backgrou @app.exception_handler(404) async def not_found_handler(request: Request, exc): - """Styled 404 page matching the FlowDeck dark theme.""" - from fastapi.responses import HTMLResponse - # API routes should get JSON, not HTML - if request.url.path.startswith("/api/") or request.url.path.startswith("/board/api/"): + """Redirect 404 HTML pages to /workspaces. API routes still get JSON.""" + # Preserve JSON 404 for all API-like paths (including /db/xxx/api) + if "/api" in request.url.path: from fastapi.responses import JSONResponse return JSONResponse({"detail": "Not found"}, status_code=404) - return HTMLResponse(NOT_FOUND_HTML, status_code=404) + from fastapi.responses import RedirectResponse + return RedirectResponse("/workspaces", status_code=302) diff --git a/tests/test_app.py b/tests/test_app.py index 0a2e3a1..33a9a80 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -1950,11 +1950,10 @@ def test_create_page_defaults_to_untitled(client): def test_styled_404_page(client): - """Unknown routes return a styled 404 HTML page.""" + """Unknown routes redirect to /workspaces.""" resp = client.get("/this-does-not-exist-xyz", follow_redirects=False) - assert resp.status_code == 404 - assert "404" in resp.text - assert "FlowDeck" in resp.text + assert resp.status_code == 302 + assert resp.headers.get("location") == "/workspaces" def test_api_404_returns_json(client):