mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
HTML error pages for FastAPI
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
parent
202ffd8923
commit
5fb4fc12de
1 changed files with 15 additions and 1 deletions
|
@ -1,4 +1,7 @@
|
|||
from fastapi import FastAPI
|
||||
import http
|
||||
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from fastapi.responses import HTMLResponse
|
||||
from starlette.middleware.sessions import SessionMiddleware
|
||||
|
||||
import aurweb.config
|
||||
|
@ -14,3 +17,14 @@ if not session_secret:
|
|||
app.add_middleware(SessionMiddleware, secret_key=session_secret)
|
||||
|
||||
app.include_router(sso.router)
|
||||
|
||||
|
||||
@app.exception_handler(HTTPException)
|
||||
async def http_exception_handler(request, exc):
|
||||
"""
|
||||
Dirty HTML error page to replace the default JSON error responses.
|
||||
In the future this should use a proper Arch-themed HTML template.
|
||||
"""
|
||||
phrase = http.HTTPStatus(exc.status_code).phrase
|
||||
return HTMLResponse(f"<h1>{exc.status_code} {phrase}</h1><p>{exc.detail}</p>",
|
||||
status_code=exc.status_code)
|
||||
|
|
Loading…
Add table
Reference in a new issue