From cac58a3f806d6d99cc8c416d9b4cd5d74ad88871 Mon Sep 17 00:00:00 2001 From: Izalia Mae Date: Sun, 21 Apr 2024 12:21:36 -0400 Subject: [PATCH] properly handle exceptions in middleware signals --- basgi/application.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/basgi/application.py b/basgi/application.py index 9bf2764..5cde94b 100644 --- a/basgi/application.py +++ b/basgi/application.py @@ -124,12 +124,8 @@ class Application(Generic[R, RT, AT]): response: Response | None = None try: - await self.on_request.handle_emit(request) + await self.on_request.handle_emit(request, catch_errors = False) - except Exception as error: - response = self._handle_error(request, error) - - try: match = self.router(request.path, request.method) request.params = match.params or {} # type: ignore[assignment] response = await match.target(request) @@ -141,7 +137,7 @@ class Application(Generic[R, RT, AT]): response = self._handle_error(request, error) try: - await self.on_response.handle_emit(request, response) + await self.on_response.handle_emit(request, response, catch_errors = False) except Exception as error: response = self._handle_error(request, error)