feat(s3-backend): add error handling to object retrieving

This commit is contained in:
2026-08-04 00:56:41 +02:00
parent 099878ba57
commit e758522d80
2 changed files with 64 additions and 0 deletions
+8
View File
@@ -13,6 +13,7 @@
# limitations under the License.
import httpx
from .exceptions import S3InternalServerError, S3ObjectNotFoundError, S3ObjectPermissionError
from typing import AsyncGenerator, Optional
from urllib.parse import urljoin
@@ -58,5 +59,12 @@ class S3Backend:
urljoin(self.url, object_path),
headers = headers
) as response:
if response.status_code == 404:
raise S3ObjectNotFoundError('Object not found', object_path = object_path)
if response.status_code == 403:
raise S3ObjectPermissionError('Object access forbidden', object_path = object_path)
if response.status_code // 100 == 5:
raise S3InternalServerError('Internal server error')
async for chunk in response.aiter_bytes():
yield chunk