Revert adding FBchatRedirectError
This commit is contained in:
@@ -96,13 +96,13 @@ class Client(object):
|
||||
self.req_counter += 1
|
||||
return payload
|
||||
|
||||
def _fix_fb_errors(self, error):
|
||||
def _fix_fb_errors(self, error_code):
|
||||
"""
|
||||
This fixes "Please try closing and re-opening your browser window" errors (1357004)
|
||||
This error usually happens after 1-2 days of inactivity
|
||||
It may be a bad idea to do this in an exception handler, if you have a better method, please suggest it!
|
||||
"""
|
||||
if isinstanceof(error, FBchatFacebookError) and error.fb_error_code == '1357004':
|
||||
if error_code == '1357004':
|
||||
log.warning('Got error #1357004. Doing a _postLogin, and resending request')
|
||||
self._postLogin()
|
||||
return True
|
||||
@@ -115,8 +115,8 @@ class Client(object):
|
||||
return r
|
||||
try:
|
||||
return check_request(r, as_json=as_json)
|
||||
except FBchatException as e:
|
||||
if error_retries > 0 and self._fix_fb_errors(e):
|
||||
except FBchatFacebookError as e:
|
||||
if error_retries > 0 and self._fix_fb_errors(e.fb_error_code):
|
||||
return self._get(url, query=query, timeout=timeout, fix_request=fix_request, as_json=as_json, error_retries=error_retries-1)
|
||||
raise e
|
||||
|
||||
@@ -127,8 +127,8 @@ class Client(object):
|
||||
return r
|
||||
try:
|
||||
return check_request(r, as_json=as_json)
|
||||
except FBchatException as e:
|
||||
if error_retries > 0 and self._fix_fb_errors(e):
|
||||
except FBchatFacebookError as e:
|
||||
if error_retries > 0 and self._fix_fb_errors(e.fb_error_code):
|
||||
return self._post(url, query=query, timeout=timeout, fix_request=fix_request, as_json=as_json, error_retries=error_retries-1)
|
||||
raise e
|
||||
|
||||
@@ -136,8 +136,8 @@ class Client(object):
|
||||
content = self._post(self.req_url.GRAPHQL, payload, fix_request=True, as_json=False)
|
||||
try:
|
||||
return graphql_response_to_json(content)
|
||||
except FBchatException as e:
|
||||
if error_retries > 0 and self._fix_fb_errors(e):
|
||||
except FBchatFacebookError as e:
|
||||
if error_retries > 0 and self._fix_fb_errors(e.fb_error_code):
|
||||
return self._graphql(payload, error_retries=error_retries-1)
|
||||
raise e
|
||||
|
||||
|
@@ -21,15 +21,6 @@ class FBchatFacebookError(FBchatException):
|
||||
self.fb_error_message = fb_error_message
|
||||
self.request_status_code = request_status_code
|
||||
|
||||
class FBchatRedirectError(Exception):
|
||||
#: The url that Facebook redirected to
|
||||
fb_redirect_url = None
|
||||
def __init__(self, message, fb_redirect_url=None):
|
||||
super(FBchatException, self).__init__(message)
|
||||
"""Thrown by fbchat when Facebook returns an unexpected redirect"""
|
||||
self.fb_redirect_url = str(fb_redirect_url)
|
||||
|
||||
|
||||
class FBchatUserError(FBchatException):
|
||||
"""Thrown by fbchat when wrong values are entered"""
|
||||
|
||||
|
@@ -187,10 +187,6 @@ def generateOfflineThreadingID():
|
||||
return str(int(msgs, 2))
|
||||
|
||||
def check_json(j):
|
||||
if not j.get('payload') and j.get('jsmods') is not None and j['jsmods'].get('require') is not None:
|
||||
for x in j['jsmods']['require']:
|
||||
if len(x) > 3 and x[0] == 'ServerRedirect' and x[1] == 'redirectPageTo':
|
||||
return FBchatRedirectError('Redirect when sending request: {}'.format(j), fb_redirect_url=x[3][0])
|
||||
if j.get('error') is None:
|
||||
return
|
||||
if 'errorDescription' in j:
|
||||
|
Reference in New Issue
Block a user