properly handle exceptions in middleware signals

This commit is contained in:
Izalia Mae 2024-04-21 12:21:36 -04:00
parent db282465d7
commit cac58a3f80

View file

@ -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)