Skip to content

Commit

Permalink
refactor(client): remove obsolete is_error_code() (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
afuetterer authored Dec 9, 2023
1 parent ac476f8 commit 1e6dfe1
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 21 deletions.
17 changes: 1 addition & 16 deletions src/oaipmh_scythe/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def harvest(self, **kwargs: str) -> OAIResponse:
"""
http_response = self._request(kwargs)
for _ in range(self.max_retries):
if self._is_error_code(http_response.status_code) and http_response.status_code in self.retry_status_codes:
if httpx.codes.is_error(http_response.status_code) and http_response.status_code in self.retry_status_codes:
retry_after = self.get_retry_after(http_response)
logger.warning("HTTP %d! Retrying after %d seconds..." % (http_response.status_code, retry_after))
time.sleep(retry_after)
Expand Down Expand Up @@ -293,18 +293,3 @@ def get_retry_after(self, http_response: httpx.Response) -> int:
except TypeError:
return self.default_retry_after
return self.default_retry_after

@staticmethod
def _is_error_code(status_code: int) -> bool:
"""Check if the given status code represents an error.
Determine whether the provided HTTP status code is indicative of an error condition.
In general, any status code equal to or greater than 400 is considered an error.
Args:
status_code: The HTTP status code to evaluate.
Returns:
A boolean indicating whether the status code represents an error.
"""
return status_code >= 400
5 changes: 0 additions & 5 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ def test_context_manager() -> None:
assert isinstance(scythe, Scythe)


def test_wrong_is_error_code(scythe: Scythe) -> None:
assert not scythe._is_error_code(200)
assert scythe._is_error_code(400)


def test_override_encoding(scythe: Scythe, respx_mock: MockRouter) -> None:
mock_route = respx_mock.get("https://zenodo.org/oai2d?metadataPrefix=oai_dc&verb=ListIdentifiers").mock(
return_value=httpx.Response(200)
Expand Down

0 comments on commit 1e6dfe1

Please sign in to comment.