feat: 404 pages → redirect to /workspaces
- main.py: @app.exception_handler(404) → RedirectResponse(/workspaces) - dashboard.py: page_detail 404 → RedirectResponse(/workspaces) - tests: test_styled_404_page → 302 redirect - API paths (containing /api) still get JSON 404, not redirect - 143 tests passent
This commit is contained in:
+5
-5
@@ -152,10 +152,10 @@ body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;backgrou
|
|||||||
|
|
||||||
@app.exception_handler(404)
|
@app.exception_handler(404)
|
||||||
async def not_found_handler(request: Request, exc):
|
async def not_found_handler(request: Request, exc):
|
||||||
"""Styled 404 page matching the FlowDeck dark theme."""
|
"""Redirect 404 HTML pages to /workspaces. API routes still get JSON."""
|
||||||
from fastapi.responses import HTMLResponse
|
# Preserve JSON 404 for all API-like paths (including /db/xxx/api)
|
||||||
# API routes should get JSON, not HTML
|
if "/api" in request.url.path:
|
||||||
if request.url.path.startswith("/api/") or request.url.path.startswith("/board/api/"):
|
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
return JSONResponse({"detail": "Not found"}, status_code=404)
|
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)
|
||||||
|
|||||||
+3
-4
@@ -1950,11 +1950,10 @@ def test_create_page_defaults_to_untitled(client):
|
|||||||
|
|
||||||
|
|
||||||
def test_styled_404_page(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)
|
resp = client.get("/this-does-not-exist-xyz", follow_redirects=False)
|
||||||
assert resp.status_code == 404
|
assert resp.status_code == 302
|
||||||
assert "404" in resp.text
|
assert resp.headers.get("location") == "/workspaces"
|
||||||
assert "FlowDeck" in resp.text
|
|
||||||
|
|
||||||
|
|
||||||
def test_api_404_returns_json(client):
|
def test_api_404_returns_json(client):
|
||||||
|
|||||||
Reference in New Issue
Block a user