generated from jCloud/repository-template
feat(s3-backend): add error handling to object retrieving
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user