Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Handle AccountLimitExceeded error from trakt #2175

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Loading