diff --git a/codecov_cli/helpers/request.py b/codecov_cli/helpers/request.py index d356eed8..048efd23 100644 --- a/codecov_cli/helpers/request.py +++ b/codecov_cli/helpers/request.py @@ -57,9 +57,9 @@ def wrapper(*args, **kwargs): while retry < MAX_RETRIES: try: response = func(*args, **kwargs) - if response.status_code == 502: + if response.status_code >= 500: logger.warning( - "Response status code was 502.", + f"Response status code was {response.status_code}.", extra=dict(extra_log_attributes=dict(retry=retry)), ) raise RetryException diff --git a/tests/helpers/test_upload_sender.py b/tests/helpers/test_upload_sender.py index 054974fc..19d6ddea 100644 --- a/tests/helpers/test_upload_sender.py +++ b/tests/helpers/test_upload_sender.py @@ -306,11 +306,13 @@ def test_upload_sender_result_fail_post_400( assert sender.warnings is not None - def test_upload_sender_result_fail_post_502( - self, mocker, mocked_responses, mocked_legacy_upload_endpoint, capsys + + @pytest.mark.parametrize("error_code", [500, 502]) + def test_upload_sender_result_fail_post_500s( + self, mocker, mocked_responses, mocked_legacy_upload_endpoint, capsys, error_code ): mocker.patch("codecov_cli.helpers.request.sleep") - mocked_legacy_upload_endpoint.status = 502 + mocked_legacy_upload_endpoint.status = error_code with pytest.raises(Exception, match="Request failed after too many retries"): _ = UploadSender().send_upload_data( @@ -318,7 +320,7 @@ def test_upload_sender_result_fail_post_502( ) matcher = re.compile( - r"(warning.*((Response status code was 502)|(Request failed\. Retrying)).*(\n)?){6}" + rf"(warning.*((Response status code was {error_code})|(Request failed\. Retrying)).*(\n)?){{6}}" ) assert matcher.match(capsys.readouterr().err) is not None