diff --git a/app/presentation/web/error_handlers.py b/app/presentation/web/error_handlers.py
index db1f162..61b9ef7 100644
--- a/app/presentation/web/error_handlers.py
+++ b/app/presentation/web/error_handlers.py
@@ -69,8 +69,10 @@ async def http_exception_handler(request: Request, exc: HTTPException) -> HTMLRe
HTMLResponse with error page.
"""
# Handle redirects (307, 308)
- if exc.status_code in (307, 308) and "Location" in exc.headers:
- return RedirectResponse(url=exc.headers["Location"], status_code=exc.status_code)
+ if exc.status_code in (307, 308):
+ location = exc.headers.get("Location") if exc.headers else None
+ if location:
+ return RedirectResponse(url=location, status_code=exc.status_code) # type: ignore[return-value]
error_pages = {
403: ("Access Denied", "You don't have permission to access this page."),
@@ -92,6 +94,7 @@ async def http_exception_handler(request: Request, exc: HTTPException) -> HTMLRe
)
return templates.TemplateResponse(
+ request,
"pages/error.html",
context,
status_code=exc.status_code,
@@ -118,6 +121,7 @@ async def not_found_handler(request: Request, exc: HTTPException) -> HTMLRespons
)
return templates.TemplateResponse(
+ request,
"pages/error.html",
context,
status_code=404,
@@ -144,6 +148,7 @@ async def forbidden_handler(request: Request, exc: HTTPException) -> HTMLRespons
)
return templates.TemplateResponse(
+ request,
"pages/error.html",
context,
status_code=403,
@@ -170,13 +175,14 @@ async def server_error_handler(request: Request, exc: Exception) -> HTMLResponse
)
return templates.TemplateResponse(
+ request,
"pages/error.html",
context,
status_code=500,
)
-def register_error_handlers(app) -> None:
+def register_error_handlers(app: Any) -> None:
"""Register error handlers with FastAPI app.
Args:
diff --git a/app/presentation/web/routes.py b/app/presentation/web/routes.py
index eb44ec1..b370a37 100644
--- a/app/presentation/web/routes.py
+++ b/app/presentation/web/routes.py
@@ -28,6 +28,21 @@ router = APIRouter(prefix="/web", tags=["web"])
templates = Jinja2Templates(directory="app/presentation/templates")
+def nl2br(value: str) -> str:
+ """Convert newlines to HTML line breaks.
+
+ Args:
+ value: String with newlines.
+
+ Returns:
+ String with
tags instead of newlines.
+ """
+ return value.replace("\n", "
\n")
+
+
+templates.env.filters["nl2br"] = nl2br
+
+
class MockPost:
"""Mock post object for UI demonstration.