Skip to content

Commit

Permalink
Merge pull request #239 from glensc/catch-ConnectionError
Browse files Browse the repository at this point in the history
Update rate_limit to also catch ConnectionError
  • Loading branch information
glensc authored Apr 16, 2021
2 parents ed6d95d + e43ae61 commit 1b50351
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions plex_trakt_sync/decorators/rate_limit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from functools import wraps
from time import sleep, time

from requests.exceptions import ConnectionError
from trakt.errors import RateLimitException
from plex_trakt_sync.logging import logger

Expand Down Expand Up @@ -41,14 +43,14 @@ def wrapper(*args, **kwargs):
try:
respect_trakt_rate()
return fn(*args, **kwargs)
except RateLimitException as e:
except (RateLimitException, ConnectionError) as e:
if retry == retries:
raise e

seconds = int(e.response.headers.get("Retry-After", 1))
retry += 1
logger.warning(
f'RateLimitException for {fn}, retrying after {seconds} seconds (try: {retry}/{retries})'
f"{e} for {fn}, retrying after {seconds} seconds (try: {retry}/{retries})"
)
sleep(seconds)

Expand Down

0 comments on commit 1b50351

Please sign in to comment.