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:
Kevin Morris 2022-01-09 22:32:49 -08:00
parent c775e8a692
commit d675c0dc26
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
10 changed files with 230 additions and 14 deletions

View file

@ -44,6 +44,8 @@ cache_pkginfo_ttl = 86400
memcache_servers = 127.0.0.1:11211
salt_rounds = 12
redis_address = redis://localhost
; Toggles traceback display in templates/errors/500.html.
traceback = 0
[ratelimit]
request_limit = 4000
@ -65,6 +67,9 @@ smtp-user =
smtp-password =
sender = notify@aur.archlinux.org
reply-to = noreply@aur.archlinux.org
; Administration email which will receive notifications about
; various server details like uncaught exceptions.
postmaster = admin@example.org
[fingerprints]
Ed25519 = SHA256:HQ03dn6EasJHNDlt51KpQpFkT3yBX83x7BoIkA1iv2k

View file

@ -37,6 +37,7 @@ memcache_servers = memcached:11211
; If cache = 'redis' this address is used to connect to Redis.
redis_address = redis://127.0.0.1
aur_request_ml = aur-requests@localhost
traceback = 1
[notifications]
; For development/testing, use /usr/bin/sendmail