diff options
author | 2024-07-11 22:54:06 +0100 | |
---|---|---|
committer | 2024-07-11 22:54:06 +0100 | |
commit | 23e6be148ee301ee660ffb9826e86ce621591d0f (patch) | |
tree | beffcfb2d2ee030d11439a29057ac3cd41a73a7c /backend/__init__.py | |
parent | Merge pull request #281 from python-discord/jb3/components/vote-field (diff) | |
parent | Ensure requested condorcet calculations are on vote components (diff) |
Merge pull request #282 from python-discord/jb3/features/condorcet-count
Add Condorcet count endpoint
Diffstat (limited to 'backend/__init__.py')
-rw-r--r-- | backend/__init__.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/backend/__init__.py b/backend/__init__.py index 67015d7..c2e1335 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -1,9 +1,12 @@ import sentry_sdk from sentry_sdk.integrations.asgi import SentryAsgiMiddleware from starlette.applications import Starlette +from starlette.exceptions import HTTPException from starlette.middleware import Middleware from starlette.middleware.authentication import AuthenticationMiddleware from starlette.middleware.cors import CORSMiddleware +from starlette.requests import Request +from starlette.responses import JSONResponse from backend import constants from backend.authentication import JWTAuthenticationBackend @@ -47,5 +50,14 @@ middleware = [ Middleware(ProtectedDocsMiddleware), ] -app = Starlette(routes=create_route_map(), middleware=middleware) + +async def http_exception(_request: Request, exc: HTTPException) -> JSONResponse: # noqa: RUF029 + return JSONResponse({"detail": exc.detail}, status_code=exc.status_code) + + +exception_handlers = {HTTPException: http_exception} + +app = Starlette( + routes=create_route_map(), middleware=middleware, exception_handlers=exception_handlers +) api.register(app) |