Skip to content

Commit

Permalink
Wrap whole request in try except (#611)
Browse files Browse the repository at this point in the history
* Wrap whole request in try except

* Wrap whole request in try except

* Wrap whole request in try except
  • Loading branch information
joostlek authored Dec 27, 2024
1 parent 669d197 commit 2b7c183
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions pytile/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,16 @@ async def _async_request(
kwargs["headers"]["tile_app_version"] = DEFAULT_APP_VERSION
kwargs["headers"]["tile_client_uuid"] = self.client_uuid

async with self._session.request(
method, f"{API_URL_SCAFFOLD}/{endpoint}", **kwargs
) as resp:
try:
try:
async with self._session.request(
method, f"{API_URL_SCAFFOLD}/{endpoint}", **kwargs
) as resp:
resp.raise_for_status()
data = await resp.json()
except ClientError as err:
if "401" in str(err):
raise InvalidAuthError("Invalid credentials") from err
raise RequestError(
f"Error requesting data from {endpoint}: {err}"
) from err
except ClientError as err:
if "401" in str(err):
raise InvalidAuthError("Invalid credentials") from err
raise RequestError(f"Error requesting data from {endpoint}: {err}") from err

LOGGER.debug("Data received from /%s: %s", endpoint, data)

Expand Down

0 comments on commit 2b7c183

Please sign in to comment.