diff --git a/sgqlc/endpoint/httpx.py b/sgqlc/endpoint/httpx.py index ee32a04..ea516d5 100644 --- a/sgqlc/endpoint/httpx.py +++ b/sgqlc/endpoint/httpx.py @@ -61,7 +61,7 @@ class HTTPXEndpoint(HTTPEndpoint): :errors: list of errors, which are objects with the key "message" and optionally others, such as "location" (for errors matching GraphQL input). Instead of raising exceptions, such as - :exc:`requests.exceptions.HTTPError` or + :exc:`requests.exceptions.HTTPStatusError` or :exc:`json.JSONDecodeError` those are stored in the "exception" key. @@ -152,7 +152,7 @@ async def runner(): try: response = await self.client.send(req) return self._parse_httpx_response(query, response) - except httpx.HTTPError as exc: + except httpx.HTTPStatusError as exc: return self._log_httpx_error(query, req, exc) return runner() diff --git a/tests/test-endpoint-httpx.py b/tests/test-endpoint-httpx.py index c046948..8c4cbf7 100644 --- a/tests/test-endpoint-httpx.py +++ b/tests/test-endpoint-httpx.py @@ -552,7 +552,7 @@ def test_server_http_non_conforming_json(respx_mock): check_respx_route(route) -def test_server_http_transport_error(respx_mock): +async def test_server_http_transport_error(respx_mock): 'Test if a transport error will get passed back to the caller' route = respx_mock.route(name='graphql', method='POST', url=test_url).mock( @@ -566,6 +566,13 @@ def test_server_http_transport_error(respx_mock): check_respx_route(route) + endpoint = HTTPXEndpoint(test_url, client=httpx.AsyncClient()) + + with pytest.raises(httpx.RemoteProtocolError): + await endpoint(graphql_query) + + check_respx_route(route) + def test_server_error_broken_json(respx_mock): 'Test if HTTP error with broken JSON payload is handled'