Adds Blueprint Group exception decorator (#2238)

* Add exception decorator

* Added tests

* Fix line too long
This commit is contained in:
Néstor Pérez
2021-09-12 21:02:59 +02:00
committed by GitHub
parent a937e08ef0
commit 404c5f9f9e
2 changed files with 53 additions and 2 deletions

View File

@@ -197,6 +197,27 @@ class BlueprintGroup(MutableSequence):
"""
self._blueprints.append(value)
def exception(self, *exceptions, **kwargs):
"""
A decorator that can be used to implement a global exception handler
for all the Blueprints that belong to this Blueprint Group.
In case of nested Blueprint Groups, the same handler is applied
across each of the Blueprints recursively.
:param args: List of Python exceptions to be caught by the handler
:param kwargs: Additional optional arguments to be passed to the
exception handler
:return a decorated method to handle global exceptions for any
blueprint registered under this group.
"""
def register_exception_handler_for_blueprints(fn):
for blueprint in self.blueprints:
blueprint.exception(*exceptions, **kwargs)(fn)
return register_exception_handler_for_blueprints
def insert(self, index: int, item: Blueprint) -> None:
"""
The Abstract class `MutableSequence` leverages this insert method to