diff --git a/singer_sdk/streams/rest.py b/singer_sdk/streams/rest.py index 563956a5f..378b32c73 100644 --- a/singer_sdk/streams/rest.py +++ b/singer_sdk/streams/rest.py @@ -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`. @@ -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) diff --git a/tests/core/rest/test_backoff.py b/tests/core/rest/test_backoff.py index fbe391e55..7a2ba39b8 100644 --- a/tests/core/rest/test_backoff.py +++ b/tests/core/rest/test_backoff.py @@ -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", @@ -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()