Ejemplo n.º 1
0
    def test_w_BadStatusCodeError(self):
        import random
        from gcloud._testing import _Monkey
        from gcloud.streaming.exceptions import BadStatusCodeError
        response = _Response(500)
        exc = BadStatusCodeError.from_response(response)
        retry_args = self._build_retry_args(exc)
        monkey, logged, slept = self._monkeyMUT()

        with _Monkey(random, uniform=lambda lower, upper: upper):
            with monkey:
                self._callFUT(retry_args)

        self._verify_logged_slept(
            logged, slept, 'Response returned status %s, retrying', (500,))
Ejemplo n.º 2
0
def _check_response(response):
    """Validate a response

    :type response: :class:`Response`
    :param response: the response to validate

    :raises: :exc:`gcloud.streaming.exceptions.RequestError` if response is
             None, :exc:`gcloud.streaming.exceptions.BadStatusCodeError` if
             response status code indicates an error, or
             :exc:`gcloud.streaming.exceptions.RetryAfterError` if response
             indicates a retry interval.
    """
    if response is None:
        # Caller shouldn't call us if the response is None, but handle anyway.
        raise RequestError('Request did not return a response.')
    elif (response.status_code >= 500
          or response.status_code == TOO_MANY_REQUESTS):
        raise BadStatusCodeError.from_response(response)
    elif response.retry_after:
        raise RetryAfterError.from_response(response)
Ejemplo n.º 3
0
def _check_response(response):
    """Validate a response

    :type response: :class:`Response`
    :param response: the response to validate

    :raises: :exc:`gcloud.streaming.exceptions.RequestError` if response is
             None, :exc:`gcloud.streaming.exceptions.BadStatusCodeError` if
             response status code indicates an error, or
             :exc:`gcloud.streaming.exceptions.RetryAfterError` if response
             indicates a retry interval.
    """
    if response is None:
        # Caller shouldn't call us if the response is None, but handle anyway.
        raise RequestError(
            'Request did not return a response.')
    elif (response.status_code >= 500 or
          response.status_code == TOO_MANY_REQUESTS):
        raise BadStatusCodeError.from_response(response)
    elif response.retry_after:
        raise RetryAfterError.from_response(response)