mirror of
https://github.com/moparisthebest/SickRage
synced 2024-12-04 15:12:23 -05:00
Try to catch situation where no response is set on error
This commit is contained in:
parent
a1871e2d43
commit
3c9adc4590
@ -29,12 +29,21 @@ class TraktAPI():
|
||||
resp.raise_for_status()
|
||||
resp = resp.json()
|
||||
except (requests.HTTPError, requests.ConnectionError) as e:
|
||||
if e.response.status_code == 502:
|
||||
code = getattr(e.response, 'status_code', None)
|
||||
if not code:
|
||||
# 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)
|
||||
elif code == 502:
|
||||
# Retry the request, cloudflare had a proxying issue
|
||||
logger.log(u"Retrying trakt api request: auth/login", logger.WARNING)
|
||||
return self.validateAccount()
|
||||
elif e.response.status_code == 401:
|
||||
elif code == 401:
|
||||
raise traktAuthException(e)
|
||||
elif code == 503:
|
||||
raise traktServerBusy(e)
|
||||
else:
|
||||
raise traktException(e)
|
||||
if 'token' in resp:
|
||||
self.token = resp['token']
|
||||
return True
|
||||
@ -58,13 +67,18 @@ class TraktAPI():
|
||||
# convert response to json
|
||||
resp = resp.json()
|
||||
except (requests.HTTPError, requests.ConnectionError) as e:
|
||||
if e.response.status_code == 502:
|
||||
code = getattr(e.response, 'status_code', None)
|
||||
if not code:
|
||||
# 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)
|
||||
elif code == 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, method)
|
||||
elif e.response.status_code == 401:
|
||||
elif code == 401:
|
||||
raise traktAuthException(e)
|
||||
elif e.response.status_code == 503:
|
||||
elif code == 503:
|
||||
raise traktServerBusy(e)
|
||||
else:
|
||||
raise traktException(e)
|
||||
|
Loading…
Reference in New Issue
Block a user