Skip to content

Commit

Permalink
refactor: adjusted constants and updated exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
MountainGod2 committed Apr 12, 2024
1 parent bc189eb commit df34514
Show file tree
Hide file tree
Showing 5 changed files with 269 additions and 243 deletions.
16 changes: 13 additions & 3 deletions examples/formatted_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ async def main() -> None:
"""Fetch Chaturbate events."""
async with ChaturbateClient(username, token, base_url=TESTBED_BASE_URL) as client:
url = None # Ensure url starts as None or a valid URL string
logger.info("Fetching Chaturbate events.")
try:
while True:
# Make sure url is a string when passed to fetch_events
Expand All @@ -42,10 +43,19 @@ async def main() -> None:
url = str(response.next_url) if response.next_url else None

# Handle exceptions
except (KeyboardInterrupt, asyncio.CancelledError, httpx.HTTPError):
logger.exception("Stopped due to an error.")
except (KeyboardInterrupt, asyncio.CancelledError):
logger.info("Exiting.")
except httpx.HTTPStatusError:
logger.exception("HTTP Status Error.")
except httpx.ReadError:
logger.exception("Read Error.")
except ValueError:
logger.exception("Value Error.")
except Exception:
logger.exception("Unexpected error.")

# Ensure the client is closed
finally:
# Close the client
await client.client.aclose()


Expand Down
Loading

0 comments on commit df34514

Please sign in to comment.