Private GIT

Skip to content
Snippets Groups Projects
Commit 4d026d72 authored by Fernando's avatar Fernando
Browse files

Merge pull request #2104 from fernandog/trakt_timeout_handle

Fix trakt exceptions when connection timed out
parents df8b0428 6cf07663
No related branches found
No related tags found
No related merge requests found
......@@ -92,18 +92,21 @@ class TraktAPI():
except requests.RequestException as e:
code = getattr(e.response, 'status_code', None)
if not code:
if 'timed out' in e:
logger.log(u'Timeout connecting to Trakt. Try to increase timeout value in Trakt settings', logger.WARNING)
# This is pretty much a fatal error if there is no status_code
# It means there basically was no response at all
raise traktException(e)
else:
logger.log(u'Could not connect to Trakt. Error: {0}'.format(e), logger.WARNING)
elif code is 502:
# Retry the request, cloudflare had a proxying issue
logger.log(u'Retrying trakt api request: %s' % path, logger.WARNING)
return self.traktRequest(path, data, headers, url, method)
elif code is 401:
logger.log(u'Unauthorized. Please check your Trakt settings', logger.WARNING)
if self.traktToken(refresh=True, count=count):
return self.traktRequest(path, data, headers, url, method)
raise traktAuthException(e)
else:
logger.log(u'Unauthorized. Please check your Trakt settings', logger.WARNING)
elif code in (500,501,503,504,520,521,522):
#http://docs.trakt.apiary.io/#introduction/status-codes
logger.log(u'Trakt may have some issues and it\'s unavailable. Try again later please', logger.WARNING)
......@@ -112,7 +115,8 @@ class TraktAPI():
logger.log(u'Trakt error (404) the resource does not exist: %s' % url + path, logger.WARNING)
return {}
else:
raise traktException(e)
logger.log(u'Could not connect to Trakt. Code error: {0}'.format(code), logger.ERROR)
return {}
# check and confirm trakt call did not fail
if isinstance(resp, dict) and resp.get('status', False) == 'failure':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment