Skip to content

Commit

Permalink
raise HawcClientException instead of timing out
Browse files Browse the repository at this point in the history
  • Loading branch information
munnsmunns committed Jan 3, 2024
1 parent 56ba6a9 commit bf8c7a2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions client/hawc_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from playwright.sync_api import Page
from playwright.sync_api._context_manager import PlaywrightContextManager as pcm

from .exceptions import HawcClientException
from .session import HawcSession


Expand Down Expand Up @@ -128,7 +129,10 @@ def download_visual(self, id: int, is_tableau: bool = False, fn: PathLike = None
BytesIO: the PNG representation of the visual, in bytes.
"""
url = f"{self.client.session.root_url}/summary/visual/{id}/"
self.page.goto(url)
# ensure response is OK before waiting
response = self.page.goto(url)
if response and not response.ok:
raise HawcClientException(response.status, response.status_text)
data = fetch_png(self.page, is_tableau)
write_to_file(data, fn)

Expand All @@ -146,7 +150,10 @@ def download_data_pivot(self, id: int, fn: PathLike = None) -> BytesIO:
BytesIO: the PNG representation of the data pivot, in bytes.
"""
url = f"{self.client.session.root_url}/summary/data-pivot/{id}/"
self.page.goto(url)
# ensure response is OK before waiting
response = self.page.goto(url)
if response and not response.ok:
raise HawcClientException(response.status, response.status_text)
data = fetch_png(self.page)
write_to_file(data, fn)
return data
Expand Down

0 comments on commit bf8c7a2

Please sign in to comment.