Skip to content

Commit

Permalink
fix: support s3 xml error messages (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
tstadel authored Dec 4, 2024
1 parent 4a84428 commit 9fcd315
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion deepset_cloud_sdk/_s3/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ async def _upload_file_with_retries(
raise RetryableHttpError(cre) from cre

try:
error_message = await response.json()
error_message = await response.text()
cre.message = cre.message + f" - {error_message}"
except Exception: # pylint: disable=broad-except
pass
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/s3/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,10 @@ async def test_upload_file_does_not_retry_for_exception(
)
with patch.object(aiohttp.ClientSession, "post") as post_mock:
post_mock.return_value.__aenter__.return_value.raise_for_status = MagicMock(side_effect=exception)
post_mock.return_value.__aenter__.return_value.json.return_value = {"error": "error"}
post_mock.return_value.__aenter__.return_value.text.return_value = "<xml>error</xml>"
s3 = S3()

with pytest.raises(aiohttp.ClientResponseError, match="reason - {'error': 'error'}"):
with pytest.raises(aiohttp.ClientResponseError, match="reason - <xml>error</xml>"):
await s3._upload_file_with_retries("one.txt", upload_session_response, "123", mock_session)

@pytest.mark.parametrize("status", [400, 422, 501])
Expand All @@ -243,7 +243,7 @@ async def test_upload_file_does_not_retry_for_exception_failing_json(
)
with patch.object(aiohttp.ClientSession, "post") as post_mock:
post_mock.return_value.__aenter__.return_value.raise_for_status = MagicMock(side_effect=exception)
post_mock.return_value.__aenter__.return_value.json.side_effect = Exception("error")
post_mock.return_value.__aenter__.return_value.text.side_effect = Exception("error")
s3 = S3()

with pytest.raises(aiohttp.ClientResponseError, match="reason"):
Expand Down

0 comments on commit 9fcd315

Please sign in to comment.