Skip to content

Commit ae19d8a

Browse files
authored
Handle non-standard status codes (#35)
Allow non-standard status codes to be passed to the status_forcelist parameter for Retry, and handled in Retry.is_retryable_status_code.
1 parent f65def3 commit ae19d8a

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.4.2] - 2025-09-02
9+
10+
### Fixed
11+
- Allow non-standard status codes to be passed to the `status_forcelist` parameter for `Retry`, and handled
12+
in `Retry.is_retryable_status_code`.
13+
814
## [0.4.1] - 2025-08-23
915

1016
### Added

httpx_retries/retry.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ def __init__(
109109
self.allowed_methods = frozenset(
110110
HTTPMethod(method.upper()) for method in (allowed_methods or self.RETRYABLE_METHODS)
111111
)
112-
self.status_forcelist = frozenset(
113-
HTTPStatus(int(code)) for code in (status_forcelist or self.RETRYABLE_STATUS_CODES)
114-
)
112+
self.status_forcelist = frozenset((status_forcelist or self.RETRYABLE_STATUS_CODES))
115113
self.retryable_exceptions = (
116114
self.RETRYABLE_EXCEPTIONS if retry_on_exceptions is None else tuple(retry_on_exceptions)
117115
)
@@ -122,7 +120,7 @@ def is_retryable_method(self, method: str) -> bool:
122120

123121
def is_retryable_status_code(self, status_code: int) -> bool:
124122
"""Check if a status code is retryable."""
125-
return HTTPStatus(status_code) in self.status_forcelist
123+
return status_code in self.status_forcelist
126124

127125
def is_retryable_exception(self, exception: httpx.HTTPError) -> bool:
128126
"""Check if an exception is retryable."""

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "httpx-retries"
7-
version = "0.4.1"
7+
version = "0.4.2"
88
description = "A retry layer for HTTPX."
99
requires-python = ">=3.9"
1010
authors = [{ name = "Will Ockmore", email = "will.ockmore@gmail.com" }]

tests/test_retry.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ def test_custom_retry_status_codes_enum() -> None:
8080
assert retry.is_retryable_status_code(502) is False
8181

8282

83+
def test_custom_retry_status_codes_non_standard() -> None:
84+
retry = Retry(status_forcelist=[523, 599])
85+
assert retry.is_retryable_status_code(523) is True
86+
assert retry.is_retryable_status_code(599) is True
87+
assert retry.is_retryable_status_code(500) is False
88+
assert retry.is_retryable_status_code(502) is False
89+
90+
8391
def test_is_exhausted() -> None:
8492
retry = Retry(total=3)
8593
assert retry.is_exhausted() is False

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)