mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-18 18:07:37 +03:00
Fix token expiry handling
This commit is contained in:
parent
fb911ef28e
commit
1ae89de163
@ -372,7 +372,7 @@ class AppWindow:
|
|||||||
try:
|
try:
|
||||||
if companion.session.login(monitor.cmdr, monitor.is_beta):
|
if companion.session.login(monitor.cmdr, monitor.is_beta):
|
||||||
self.status['text'] = ''
|
self.status['text'] = ''
|
||||||
except companion.ServerError as e:
|
except (companion.CredentialsError, companion.ServerError, companion.ServerLagging) as e:
|
||||||
self.status['text'] = unicode(e)
|
self.status['text'] = unicode(e)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if __debug__: print_exc()
|
if __debug__: print_exc()
|
||||||
|
18
companion.py
18
companion.py
@ -280,6 +280,7 @@ class Session:
|
|||||||
os.environ['REQUESTS_CA_BUNDLE'] = join(config.respath, 'cacert.pem')
|
os.environ['REQUESTS_CA_BUNDLE'] = join(config.respath, 'cacert.pem')
|
||||||
|
|
||||||
def login(self, cmdr=None, is_beta=None):
|
def login(self, cmdr=None, is_beta=None):
|
||||||
|
# Returns True if login succeeded, False if re-authorization initiated.
|
||||||
if not CLIENT_ID:
|
if not CLIENT_ID:
|
||||||
raise CredentialsError()
|
raise CredentialsError()
|
||||||
if not cmdr or is_beta is None:
|
if not cmdr or is_beta is None:
|
||||||
@ -341,21 +342,20 @@ class Session:
|
|||||||
if __debug__: print_exc()
|
if __debug__: print_exc()
|
||||||
raise ServerError()
|
raise ServerError()
|
||||||
|
|
||||||
if r.status_code != requests.codes.ok:
|
try:
|
||||||
|
r.raise_for_status()
|
||||||
|
data = r.json() # Will fail here if token expired since response is empty
|
||||||
|
except:
|
||||||
# Start again - maybe our token expired
|
# Start again - maybe our token expired
|
||||||
self.dump(r)
|
self.dump(r)
|
||||||
self.close()
|
self.close()
|
||||||
if self.login():
|
if self.login():
|
||||||
return self.query(endpoint)
|
return self.query(endpoint)
|
||||||
|
else:
|
||||||
|
raise CredentialsError()
|
||||||
|
|
||||||
try:
|
if 'timestamp' not in data:
|
||||||
data = r.json()
|
data['timestamp'] = time.strftime('%Y-%m-%dT%H:%M:%SZ', parsedate(r.headers['Date']))
|
||||||
if 'timestamp' not in data:
|
|
||||||
data['timestamp'] = time.strftime('%Y-%m-%dT%H:%M:%SZ', parsedate(r.headers['Date']))
|
|
||||||
except:
|
|
||||||
self.dump(r)
|
|
||||||
raise ServerError()
|
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def profile(self):
|
def profile(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user