diff --git a/app/__init__.py b/app/__init__.py index 7c422cd..b02a3c4 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -6,6 +6,7 @@ Creates and configures the FastAPI application with all routers and middleware. from pathlib import Path from fastapi import FastAPI, Request +from fastapi.responses import JSONResponse from fastapi.staticfiles import StaticFiles from artdag_common import create_jinja_env @@ -41,6 +42,18 @@ def create_app() -> FastAPI: template_dir = Path(__file__).parent / "templates" app.state.templates = create_jinja_env(template_dir) + # Custom 404 handler + @app.exception_handler(404) + async def not_found_handler(request: Request, exc): + from artdag_common.middleware import wants_html + if wants_html(request): + from artdag_common import render + return render(app.state.templates, "404.html", request, + user=None, + status_code=404, + ) + return JSONResponse({"detail": "Not found"}, status_code=404) + # Include routers from .routers import auth, storage, api, recipes, cache, runs, home diff --git a/app/templates/404.html b/app/templates/404.html new file mode 100644 index 0000000..0cd9c70 --- /dev/null +++ b/app/templates/404.html @@ -0,0 +1,14 @@ +{% extends "base.html" %} + +{% block title %}Not Found - Art-DAG L1{% endblock %} + +{% block content %} +
The page you're looking for doesn't exist or has been moved.
+ + Go Home + +