def should_retry(self, error, retries_attempted):
"""Return true if the http client should retry the request.
:param error: the caught error.
:type error: Exception
:param retries_attempted: the number of retries which has been attempted before.
:type retries_attempted: int
:return: true if the http client should retry the request.
:rtype: bool
"""
# stop retrying when the maximum number of retries is reached
if retries_attempted >= self.max_error_retry:
return False
# always retry on IOError
if isinstance(error, IOError):
_logger.debug('Retry for IOError.')
return True
# Only retry on a subset of service exceptions
if isinstance(error, BceServerError):
if error.status_code == httplib.INTERNAL_SERVER_ERROR:
_logger.debug('Retry for internal server error.')
return True
if error.status_code == httplib.SERVICE_UNAVAILABLE:
_logger.debug('Retry for service unavailable.')
return True
if error.code == BceServerError.REQUEST_EXPIRED:
_logger.debug('Retry for request expired.')
return True
return False
评论列表
文章目录