示例#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)
示例#2
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
示例#3
0
 def test_is_client_error(self):
     self.assertTrue(status.is_client_error(403))
示例#4
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}")
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)
示例#6
0
 def test_is_client_error(self):
     self.assertTrue(status.is_client_error(403))