mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
feat(python): catch all exceptions thrown through fastapi route paths
This commit does quite a bit: - Catches unhandled exceptions raised in the route handler and produces a 500 Internal Server Error Arch-themed response. - Each unhandled exception causes a notification to be sent to new `notifications.postmaster` email with a "Traceback ID." - Traceback ID is logged to the server along with the traceback which caused the 500: `docker-compose logs fastapi | grep '<traceback_id>'` - If `options.traceback` is set to `1`, traceback is displayed in the new 500.html template. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
c775e8a692
commit
d675c0dc26
10 changed files with 230 additions and 14 deletions
|
@ -1,3 +1,5 @@
|
|||
import re
|
||||
|
||||
from datetime import datetime
|
||||
from http import HTTPStatus
|
||||
from unittest import mock
|
||||
|
@ -322,9 +324,13 @@ def test_generate_unique_sid_exhausted(client: TestClient, user: User,
|
|||
response = request.post("/login", data=post_data, cookies={})
|
||||
assert response.status_code == int(HTTPStatus.INTERNAL_SERVER_ERROR)
|
||||
|
||||
expected = "Unable to generate a unique session ID"
|
||||
assert expected in response.text
|
||||
assert "500 - Internal Server Error" in response.text
|
||||
|
||||
# Make sure an IntegrityError from the DB got logged out.
|
||||
# Make sure an IntegrityError from the DB got logged out
|
||||
# with a FATAL traceback ID.
|
||||
expr = r"FATAL\[.{7}\]"
|
||||
assert re.search(expr, caplog.text)
|
||||
assert "IntegrityError" in caplog.text
|
||||
|
||||
expr = r"Duplicate entry .+ for key .+SessionID.+"
|
||||
assert re.search(expr, response.text)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue