From ada51c08805c114604c63f6199be540edcad9a27 Mon Sep 17 00:00:00 2001 From: giles Date: Sun, 11 Jan 2026 13:14:29 +0000 Subject: [PATCH] Add 404 handler and template Co-Authored-By: Claude Opus 4.5 --- app/__init__.py | 13 +++++++++++++ app/templates/404.html | 14 ++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 app/templates/404.html 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 %} +
+

404

+

Page Not Found

+

The page you're looking for doesn't exist or has been moved.

+ + Go Home + +
+{% endblock %}