Skip to content

Commit

Permalink
make error classes more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
bh2smith committed Sep 8, 2023
1 parent f7ade87 commit 2aa3ad0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dune_client/api/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def upload_csv(self, table_name: str, data: str, description: str = "") -> bool:
try:
return bool(response_json["success"])
except KeyError as err:
raise DuneError(response_json, "upload_csv response", err) from err
raise DuneError(response_json, "UploadCsvResponse", err) from err

######################
# Deprecated Functions
Expand Down
18 changes: 12 additions & 6 deletions dune_client/api/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def create_query(
# Note that this requires an extra request.
return self.get_query(query_id)
except KeyError as err:
raise DuneError(response_json, "create_query Response", err) from err
raise DuneError(response_json, "CreateQueryResponse", err) from err

def get_query(self, query_id: int) -> DuneQuery:
"""
Expand Down Expand Up @@ -96,7 +96,7 @@ def update_query( # pylint: disable=too-many-arguments
# No need to make a dataclass for this since it's just a boolean.
return int(response_json["query_id"])
except KeyError as err:
raise DuneError(response_json, "update_query Response", err) from err
raise DuneError(response_json, "UpdateQueryResponse", err) from err

def archive_query(self, query_id: int) -> bool:
"""
Expand All @@ -108,7 +108,7 @@ def archive_query(self, query_id: int) -> bool:
# No need to make a dataclass for this since it's just a boolean.
return self.get_query(int(response_json["query_id"])).meta.is_archived
except KeyError as err:
raise DuneError(response_json, "make_private Response", err) from err
raise DuneError(response_json, "ArchiveQueryResponse", err) from err

def unarchive_query(self, query_id: int) -> bool:
"""
Expand All @@ -120,18 +120,24 @@ def unarchive_query(self, query_id: int) -> bool:
# No need to make a dataclass for this since it's just a boolean.
return self.get_query(int(response_json["query_id"])).meta.is_archived
except KeyError as err:
raise DuneError(response_json, "make_private Response", err) from err
raise DuneError(response_json, "UnarchiveQueryResponse", err) from err

def make_private(self, query_id: int) -> None:
"""
https://dune.com/docs/api/api-reference/edit-queries/private-query
"""
response_json = self._post(route=f"/query/{query_id}/private")
assert self.get_query(int(response_json["query_id"])).meta.is_private
try:
assert self.get_query(int(response_json["query_id"])).meta.is_private
except KeyError as err:
raise DuneError(response_json, "MakePrivateResponse", err) from err

def make_public(self, query_id: int) -> None:
"""
https://dune.com/docs/api/api-reference/edit-queries/private-query
"""
response_json = self._post(route=f"/query/{query_id}/unprivate")
assert not self.get_query(int(response_json["query_id"])).meta.is_private
try:
assert not self.get_query(int(response_json["query_id"])).meta.is_private
except KeyError as err:
raise DuneError(response_json, "MakePublicResponse", err) from err

0 comments on commit 2aa3ad0

Please sign in to comment.