Blueprint specific exception handlers (#2208)

This commit is contained in:
Adam Hopkins
2021-08-31 12:32:51 +03:00
committed by GitHub
parent 945885d501
commit 69c5dde9bf
4 changed files with 57 additions and 31 deletions

View File

@@ -334,7 +334,11 @@ class Sanic(BaseSanic, metaclass=TouchUpMeta):
self.named_response_middleware[_rn].appendleft(middleware)
return middleware
def _apply_exception_handler(self, handler: FutureException):
def _apply_exception_handler(
self,
handler: FutureException,
route_names: Optional[List[str]] = None,
):
"""Decorate a function to be registered as a handler for exceptions
:param exceptions: exceptions
@@ -344,9 +348,9 @@ class Sanic(BaseSanic, metaclass=TouchUpMeta):
for exception in handler.exceptions:
if isinstance(exception, (tuple, list)):
for e in exception:
self.error_handler.add(e, handler.handler)
self.error_handler.add(e, handler.handler, route_names)
else:
self.error_handler.add(exception, handler.handler)
self.error_handler.add(exception, handler.handler, route_names)
return handler.handler
def _apply_listener(self, listener: FutureListener):