Skip to content

Commit

Permalink
fix: Retry all 5xx status codes (#2035)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
asamasoma and pre-commit-ci[bot] authored Nov 8, 2023
1 parent f4a86df commit 8022703
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 2 additions & 4 deletions singer_sdk/streams/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def requests_session(self) -> requests.Session:
def validate_response(self, response: requests.Response) -> None:
"""Validate HTTP response.
Checks for error status codes and wether they are fatal or retriable.
Checks for error status codes and whether they are fatal or retriable.
In case an error is deemed transient and can be safely retried, then this
method should raise an :class:`singer_sdk.exceptions.RetriableAPIError`.
Expand Down Expand Up @@ -179,9 +179,7 @@ def validate_response(self, response: requests.Response) -> None:
"""
if (
response.status_code in self.extra_retry_statuses
or HTTPStatus.INTERNAL_SERVER_ERROR
<= response.status_code
<= max(HTTPStatus)
or response.status_code >= HTTPStatus.INTERNAL_SERVER_ERROR
):
msg = self.response_error_message(response)
raise RetriableAPIError(msg, response)
Expand Down
10 changes: 9 additions & 1 deletion tests/core/rest/test_backoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ def custom_validation_stream(rest_tap):
match=r"503 Server Error: Service Unavailable for path: /dummy",
),
),
(
521, # Cloudflare custom status code higher than max(HTTPStatus)
"Web Server Is Down",
pytest.raises(
RetriableAPIError,
match=r"521 Server Error: Web Server Is Down for path: /dummy",
),
),
(
429,
"Too Many Requests",
Expand All @@ -84,7 +92,7 @@ def custom_validation_stream(rest_tap):
),
(200, "OK", nullcontext()),
],
ids=["client-error", "server-error", "rate-limited", "ok"],
ids=["client-error", "server-error", "server-error", "rate-limited", "ok"],
)
def test_status_code_api(basic_rest_stream, status_code, reason, expectation):
fake_response = requests.Response()
Expand Down

0 comments on commit 8022703

Please sign in to comment.