add retry error handling to _chunks()

Signed-off-by: NicholasTanz <nicholastanzillo@gmail.com>
This commit is contained in:
NicholasTanz 2025-01-09 23:56:06 -05:00
parent 2aed81f019
commit a48fca51f9
2 changed files with 8 additions and 3 deletions

View file

@ -109,7 +109,11 @@ def test_http_error(self) -> None:
def test_response_read_timeout(self, mock_session_get: Mock) -> None:
mock_response = Mock()
mock_response.status = 200
attr = {"stream.side_effect": urllib3.exceptions.TimeoutError}
attr = {"stream.side_effect": urllib3.exceptions.MaxRetryError(
urllib3.connectionpool.ConnectionPool("localhost"),
"",
urllib3.exceptions.TimeoutError(),
)}
mock_response.configure_mock(**attr)
mock_session_get.return_value = mock_response

View file

@ -103,8 +103,9 @@ def _chunks(
try:
yield from response.stream(self.chunk_size)
except urllib3.exceptions.TimeoutError as e:
raise exceptions.SlowRetrievalError from e
except urllib3.exceptions.MaxRetryError as e:
if isinstance(e.reason, urllib3.exceptions.TimeoutError):
raise exceptions.SlowRetrievalError from e
finally:
response.release_conn()