base ui #11
@@ -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:
|
||||
|
||||
@@ -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 <br> tags instead of newlines.
|
||||
"""
|
||||
return value.replace("\n", "<br>\n")
|
||||
|
||||
|
||||
templates.env.filters["nl2br"] = nl2br
|
||||
|
||||
|
||||
class MockPost:
|
||||
"""Mock post object for UI demonstration.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user