Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
---------

1.0.7
~~~~~

* Update ClientConnectionError to deal with httpx.NetworkError exceptions (thanks @depauwjimmy).

1.0.6
~~~~~

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
httpx>=0.13.2
httpx>=0.13.3
python-slugify>=4.0.0
python-status>=1.0.1
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
changelog = f.read()


install_requirements = ["python-status>=1.0.1", "httpx>=0.13.2", "python-slugify>=4.0.0"]
install_requirements = ["python-status>=1.0.1", "httpx>=0.13.3", "python-slugify>=4.0.0"]
tests_requirements = ["pytest", "pytest-asyncio", "pytest-cov", "pytest-httpserver", "coveralls"]


Expand Down
15 changes: 11 additions & 4 deletions simple_rest_client/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
from .exceptions import AuthError, ClientConnectionError, ClientError, NotFoundError, ServerError

logger = logging.getLogger(__name__)
client_connection_exceptions = (
httpx.ConnectTimeout,
httpx.ReadTimeout,
httpx.WriteTimeout,
httpx.PoolTimeout,
httpx.NetworkError,
)


def validate_response(response):
Expand All @@ -26,9 +33,9 @@ def handle_request_error(f):
def wrapper(*args, **kwargs):
try:
response = f(*args, **kwargs)
except (httpx.ConnectTimeout, httpx.ReadTimeout, httpx.WriteTimeout, httpx.PoolTimeout) as exc:
except client_connection_exceptions as exc:
logger.exception(exc)
raise ClientConnectionError() from exc
raise ClientConnectionError(exc)

validate_response(response)

Expand All @@ -41,9 +48,9 @@ def handle_async_request_error(f):
async def wrapper(*args, **kwargs):
try:
response = await f(*args, **kwargs)
except (httpx.ConnectTimeout, httpx.ReadTimeout, httpx.WriteTimeout, httpx.PoolTimeout) as exc:
except client_connection_exceptions as exc:
logger.exception(exc)
raise ClientConnectionError() from exc
raise ClientConnectionError(exc)

validate_response(response)

Expand Down
11 changes: 8 additions & 3 deletions tests/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,20 @@ def test_validate_response_client_error(status_code, response_kwargs):


@pytest.mark.parametrize(
"side_effect", (httpx.ConnectTimeout, httpx.ReadTimeout, httpx.WriteTimeout, httpx.PoolTimeout),
"side_effect",
(httpx.ConnectTimeout, httpx.ReadTimeout, httpx.WriteTimeout, httpx.PoolTimeout, httpx.NetworkError),
)
def test_handle_request_error_exceptions(side_effect):
wrapped = mock.Mock(side_effect=side_effect)
with pytest.raises(ClientConnectionError):
handle_request_error(wrapped)()


def test_handle_async_request_error_exceptions(event_loop):
wrapped = CoroutineMock(side_effect=httpx.ReadTimeout)
@pytest.mark.parametrize(
"side_effect",
(httpx.ConnectTimeout, httpx.ReadTimeout, httpx.WriteTimeout, httpx.PoolTimeout, httpx.NetworkError),
)
def test_handle_async_request_error_exceptions(event_loop, side_effect):
wrapped = CoroutineMock(side_effect=side_effect)
with pytest.raises(ClientConnectionError):
event_loop.run_until_complete(handle_async_request_error(wrapped)())