From 4308136108886301074e6b034249757cb835e3e0 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 23 Aug 2021 17:12:11 +0200 Subject: [PATCH] root: fix error_handler for websocket Signed-off-by: Jens Langhammer --- authentik/root/asgi/error_handler.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/authentik/root/asgi/error_handler.py b/authentik/root/asgi/error_handler.py index 1124b56f5..5b2c26308 100644 --- a/authentik/root/asgi/error_handler.py +++ b/authentik/root/asgi/error_handler.py @@ -19,14 +19,21 @@ class ASGIErrorHandler: return await self.app(scope, receive, send) except Exception as exc: # pylint: disable=broad-except LOGGER.warning("Fatal ASGI exception", exc=exc) - return await self.error_handler(send) + return await self.error_handler(scope, send) - async def error_handler(self, send: Send) -> None: + async def error_handler(self, scope: Scope, send: Send) -> None: """Return a generic error message""" + if scope.get("scheme", "http") == "http": + return await send( + { + "type": "http.request", + "body": b"Internal server error", + "more_body": False, + } + ) return await send( { - "type": "http.request", - "body": b"Internal server error", - "more_body": False, + "type": "websocket.send", + "text": b"Internal server error", } )