fix: error handling for S3 file loading in py and ts clients (#6124)

This commit is contained in:
HugoCasa
2025-07-02 23:28:13 +02:00
committed by GitHub
parent 4f77fdeeb0
commit 23d624aa23
2 changed files with 22 additions and 2 deletions

View File

@@ -22,6 +22,17 @@ class S3BufferedReader(BufferedReader):
def __enter__(self):
reader = self._context_manager.__enter__()
if reader.status_code >= 400:
error_bytes = reader.read()
try:
error_text = error_bytes.decode('utf-8')
except UnicodeDecodeError:
error_text = str(error_bytes)
raise httpx.HTTPStatusError(
f"Failed to load S3 file: {reader.status_code} {reader.reason_phrase} - {error_text}",
request=reader.request,
response=reader
)
self._iterator = reader.iter_bytes()
return self