core: improve error handling on ASGI level (#10547)

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens L.
2024-07-19 17:17:42 +02:00
committed by GitHub
parent 6eb6e48cbc
commit f83838003b
6 changed files with 10 additions and 8 deletions

View File

@ -274,9 +274,13 @@ class ChannelsLoggingMiddleware:
self.log(scope)
try:
return await self.inner(scope, receive, send)
except DenyConnection:
return await send({"type": "websocket.close"})
except Exception as exc:
if settings.DEBUG:
raise exc
LOGGER.warning("Exception in ASGI application", exc=exc)
raise DenyConnection() from None
return await send({"type": "websocket.close"})
def log(self, scope: dict, **kwargs):
"""Log request"""