From 7cd5de59b63f4372e84a34ee412563b654b41edc Mon Sep 17 00:00:00 2001 From: John Bywater Date: Thu, 25 May 2017 21:57:25 +0100 Subject: [PATCH] Enhanced retry decorator, to accept a list of exception classes. --- eventsourcing/domain/model/decorators.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/eventsourcing/domain/model/decorators.py b/eventsourcing/domain/model/decorators.py index 92e8917c1..de2d9a732 100644 --- a/eventsourcing/domain/model/decorators.py +++ b/eventsourcing/domain/model/decorators.py @@ -169,8 +169,13 @@ def wrapper(*args, **kwargs): else: # Check decorator args, and return _retry, # to be called with the decorated function. - if not (isinstance(exc, type) and issubclass(exc, Exception)): - raise TypeError("'exc' must be an exception class: {}".format(exc)) + if isinstance(exc, (list, tuple)): + for _exc in exc: + if not (isinstance(_exc, type) and issubclass(_exc, Exception)): + raise TypeError("not an exception class: {}".format(_exc)) + else: + if not (isinstance(exc, type) and issubclass(exc, Exception)): + raise TypeError("not an exception class: {}".format(exc)) if not isinstance(max_retries, int): raise TypeError("'max' must be an int: {}".format(max_retries)) if not isinstance(wait, (float, int)):