Skip to content

Commit

Permalink
Handle AccountLimitExceeded error from trakt
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed Feb 3, 2025
1 parent d13a3ea commit 8fcfbaa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 11 additions & 2 deletions plextraktsync/decorators/rate_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from click import ClickException
from decorator import decorator
from trakt.errors import RateLimitException
from trakt.errors import AccountLimitExceeded, RateLimitException

from plextraktsync.factory import logging

Expand All @@ -18,7 +18,15 @@ def rate_limit(fn, retries=5, *args, **kwargs):
while True:
try:
return fn(*args, **kwargs)
except RateLimitException as e:
except (RateLimitException, AccountLimitExceeded) as e:
if isinstance(e, AccountLimitExceeded):
logger.error(f"Trakt Error: {e}")
logger.error(f"Trakt Limit: {e.account_limit}")
logger.error(f"Trakt Details: {e.details}")
logger.error(f"Trakt headers: {e.response.headers}")
logger.error(f"Trakt content: {e.response.content}")
raise ClickException("Skip Retry")

if retry == retries:
logger.error(f"Trakt Error: {e}")
logger.error(f"Last call: {fn.__module__}.{fn.__name__}({args[1:]}, {kwargs})")
Expand All @@ -28,4 +36,5 @@ def rate_limit(fn, retries=5, *args, **kwargs):
retry += 1
logger.warning(f"{e} for {fn.__module__}.{fn.__name__}(), retrying after {seconds} seconds (try: {retry}/{retries})")
logger.debug(e.details)
raise ClickException("Skip Retry")
sleep(seconds)
2 changes: 2 additions & 0 deletions plextraktsync/decorators/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def retry(fn, retries=5, *args, **kwargs):
TraktBadGateway,
TraktUnavailable,
TraktInternalException,
# TraktInternalException,
) as e:
if count == retries:
logger.error(f"Error: {e}")
Expand All @@ -48,3 +49,4 @@ def retry(fn, retries=5, *args, **kwargs):
count += 1
logger.warning(f"{e} for {fn.__module__}.{fn.__name__}(), retrying after {seconds} seconds (try: {count}/{retries})")
sleep(seconds)
raise ClickException("EEE")

0 comments on commit 8fcfbaa

Please sign in to comment.