diff --git a/lazy_github/lib/github/notifications.py b/lazy_github/lib/github/notifications.py index a95e099..9cfd7c4 100644 --- a/lazy_github/lib/github/notifications.py +++ b/lazy_github/lib/github/notifications.py @@ -1,6 +1,7 @@ import json from lazy_github.lib.github.backends.cli import run_gh_cli_command +from lazy_github.lib.logging import lg from lazy_github.models.github import Notification NOTIFICATIONS_PAGE_COUNT = 30 @@ -8,16 +9,22 @@ async def fetch_notifications(all: bool) -> list[Notification]: """Fetches notifications on GitHub. If all=True, then previously read notifications will also be returned""" - result = await run_gh_cli_command(["api", f"/notifications?all={str(all).lower()}"]) notifications: list[Notification] = [] - if result.stdout: - parsed = json.loads(result.stdout) - notifications = [Notification(**n) for n in parsed] + try: + result = await run_gh_cli_command(["api", f"/notifications?all={str(all).lower()}"]) + if result.stdout: + parsed = json.loads(result.stdout) + notifications = [Notification(**n) for n in parsed] + except Exception: + lg.exception("Failed to retrieve notifications from the Github API") return notifications async def mark_notification_as_read(notification: Notification) -> None: - await run_gh_cli_command(["--method", "PATCH", "api", f"/notifications/threads/{notification.id}"]) + try: + await run_gh_cli_command(["--method", "PATCH", "api", f"/notifications/threads/{notification.id}"]) + except Exception: + lg.exception("Failed to mark notification as read") async def unread_notification_count() -> int: