Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Marcus Andersson
aurweb
Commits
5fb4fc12
Commit
5fb4fc12
authored
Jul 28, 2020
by
Frédéric Mangano-Tarumi
Committed by
Lukas Fleischer
Feb 20, 2021
Browse files
HTML error pages for FastAPI
Signed-off-by:
Lukas Fleischer
<
lfleischer@archlinux.org
>
parent
202ffd89
Changes
1
Hide whitespace changes
Inline
Side-by-side
aurweb/asgi.py
View file @
5fb4fc12
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
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment