Files
Aniworld/src/server/controllers/error_controller.py
Lukas 99e24a2fc3 feat: Integrate HTML templates with FastAPI
- Created template_helpers.py for centralized template rendering
- Added ux_features.css for enhanced UX styling
- Implemented JavaScript modules for:
  - Keyboard shortcuts (Ctrl+K, Ctrl+R navigation)
  - User preferences persistence
  - Undo/redo functionality (Ctrl+Z/Ctrl+Y)
  - Mobile responsive features
  - Touch gesture support
  - Accessibility features (ARIA, focus management)
  - Screen reader support
  - Color contrast compliance (WCAG)
  - Multi-screen support
- Updated page_controller.py and error_controller.py to use template helpers
- Created comprehensive template integration tests
- All templates verified: index.html, login.html, setup.html, queue.html, error.html
- Maintained responsive layout and theme switching
- Updated instructions.md (removed completed task)
- Updated infrastructure.md with template integration details
2025-10-17 12:01:22 +02:00

40 lines
1.2 KiB
Python

"""
Error handler controller for managing application exceptions.
This module provides custom error handlers for different HTTP status codes.
"""
from fastapi import HTTPException, Request
from fastapi.responses import JSONResponse
from src.server.utils.template_helpers import render_template
async def not_found_handler(request: Request, exc: HTTPException):
"""Custom 404 handler."""
if request.url.path.startswith("/api/"):
return JSONResponse(
status_code=404,
content={"detail": "API endpoint not found"}
)
return render_template(
"error.html",
request,
context={"error": "Page not found", "status_code": 404},
title="404 - Not Found"
)
async def server_error_handler(request: Request, exc: Exception):
"""Custom 500 handler."""
if request.url.path.startswith("/api/"):
return JSONResponse(
status_code=500,
content={"detail": "Internal server error"}
)
return render_template(
"error.html",
request,
context={"error": "Internal server error", "status_code": 500},
title="500 - Server Error"
)