def _handles_connection_error(func):
"""
Decorator for handling ConnectionErrors raised by the requests
library, raises a BrainServerError instead.
:param func: the function being decorated
"""
@functools.wraps(func)
def _handler(self, url, *args, **kwargs):
try:
return func(self, url, *args, **kwargs)
except requests.exceptions.ConnectionError as e:
message = "Unable to connect to domain: {}".format(url)
raise BrainServerError(message)
return _handler
评论列表
文章目录