mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-14 08:17:13 +03:00
Fix token expiry handling
This commit is contained in:
parent
fb911ef28e
commit
1ae89de163
@ -372,7 +372,7 @@ class AppWindow:
|
||||
try:
|
||||
if companion.session.login(monitor.cmdr, monitor.is_beta):
|
||||
self.status['text'] = ''
|
||||
except companion.ServerError as e:
|
||||
except (companion.CredentialsError, companion.ServerError, companion.ServerLagging) as e:
|
||||
self.status['text'] = unicode(e)
|
||||
except Exception as e:
|
||||
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')
|
||||
|
||||
def login(self, cmdr=None, is_beta=None):
|
||||
# Returns True if login succeeded, False if re-authorization initiated.
|
||||
if not CLIENT_ID:
|
||||
raise CredentialsError()
|
||||
if not cmdr or is_beta is None:
|
||||
@ -341,21 +342,20 @@ class Session:
|
||||
if __debug__: print_exc()
|
||||
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
|
||||
self.dump(r)
|
||||
self.close()
|
||||
if self.login():
|
||||
return self.query(endpoint)
|
||||
else:
|
||||
raise CredentialsError()
|
||||
|
||||
try:
|
||||
data = r.json()
|
||||
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()
|
||||
|
||||
if 'timestamp' not in data:
|
||||
data['timestamp'] = time.strftime('%Y-%m-%dT%H:%M:%SZ', parsedate(r.headers['Date']))
|
||||
return data
|
||||
|
||||
def profile(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user