Ejemplo n.º 1
0
def validate_response(response):
    error_suffix = " response={!r}".format(response)
    if response.status_code in (status.HTTP_401_UNAUTHORIZED, status.HTTP_403_FORBIDDEN):
        raise AuthError("operation=auth_error," + error_suffix, response)
    if response.status_code == status.HTTP_404_NOT_FOUND:
        raise NotFoundError("operation=not_found_error," + error_suffix, response)
    if status.is_client_error(code=response.status_code):
        raise ClientError("operation=client_error," + error_suffix, response)
    if status.is_server_error(code=response.status_code):
        raise ServerError("operation=server_error," + error_suffix, response)
Ejemplo n.º 2
0
def validate_status_code(status_code, content):
    exception_class = None
    if status_code in (status.HTTP_401_UNAUTHORIZED, status.HTTP_403_FORBIDDEN):
        exception_class = AuthError(status_code, {'errorMessage': 'Authentication Error'})
    elif status_code == status.HTTP_404_NOT_FOUND:
        exception_class = NotFound(status_code, {'errorMessage': 'Endpoint Not Found'})
    elif status_code in range(status.HTTP_400_BAD_REQUEST, status.HTTP_417_EXPECTATION_FAILED + 1):
        exception_class = OandaError(status_code, content)
    elif status.is_server_error(status_code):
        exception_class = ServerError(status_code)

    if exception_class:
        return False, exception_class
    return True, exception_class
Ejemplo n.º 3
0
    def _make_request(self, method, url, **kwargs):
        request_method = getattr(self.session, method.lower())

        try:
            response = request_method(url, timeout=self.timeout, **kwargs)
        except (ConnectionError, Timeout) as exc:
            raise ClientConnectionError(exc)

        if status.is_client_error(code=response.status_code):
            raise ClientError(response)

        if status.is_server_error(code=response.status_code):
            raise ServerError(response)

        return response
Ejemplo n.º 4
0
 def test_is_server_error(self):
     self.assertTrue(status.is_server_error(500))
Ejemplo n.º 5
0
def raise_for_status(res: HTTPResponse) -> None:
    if status.is_client_error(res.status) or status.is_server_error(
            res.status):
        raise HTTPError(f"{res.status}:{res.reason}")
Ejemplo n.º 6
0
def validate_response(response):
    error_suffix = ' response={!r}'.format(response)
    if status.is_client_error(code=response.status_code):
        raise ClientError('operation=client_error,' + error_suffix, response)
    if status.is_server_error(code=response.status_code):
        raise ServerError('operation=server_error,' + error_suffix, response)
Ejemplo n.º 7
0
 def test_is_server_error(self):
     self.assertTrue(status.is_server_error(500))