Skip to content

Commit

Permalink
feat: create custom StorageException
Browse files Browse the repository at this point in the history
  • Loading branch information
anand2312 committed Oct 13, 2021
1 parent b5f7316 commit 55e7eef
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions supabase/lib/storage/storage_bucket_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
from datetime import datetime
from typing import Any, Literal, Optional, Type, Union

from httpx import AsyncClient, Client
from httpx import AsyncClient, Client, HTTPError

__all__ = ["Bucket", "StorageBucketAPI"]

_RequestMethod = Literal["GET", "POST", "PUT", "DELETE", "PATCH"]


class StorageException(Exception):
"""Error raised when an operation on the storage API fails."""


@dataclass
class Bucket:
id: str
Expand Down Expand Up @@ -79,7 +83,10 @@ def _sync_request(
return

response = self._client.request(method, url, json=json)
response.raise_for_status()
try:
response.raise_for_status()
except HTTPError:
raise StorageException(response.json())

response_data = response.json()

Expand All @@ -104,7 +111,10 @@ async def _async_request(
return

response = await self._client.request(method, url, json=json)
response.raise_for_status()
try:
response.raise_for_status()
except HTTPError:
raise StorageException(response.json())

response_data = response.json()

Expand Down

0 comments on commit 55e7eef

Please sign in to comment.