mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-13 15:57:14 +03:00
CAPI: Handle when we get no 'commander' in returned data.
I was testing the new Steam or Epic CAPI auth. My EGS account hasn't yet been used, so has no commander attached. EDMC thinks the auth has succeeded in this case, but hitting 'Update' causes it to error because the returned data is empty. So, add some checks for lack of 'commander' key and a specific message "CAPI: No commander data returned" for status line. Without this there's a KeyError exception thrown, causing the status line to just get 'commander' in it, which isn't helpful.
This commit is contained in:
parent
e3d2fa40b7
commit
b11be09b56
@ -662,17 +662,25 @@ class AppWindow(object):
|
||||
config.set('querytime', querytime)
|
||||
|
||||
# Validation
|
||||
if not data.get('commander', {}).get('name'):
|
||||
if 'commander' not in data:
|
||||
# This can happen with EGS Auth if no commander created yet
|
||||
self.status['text'] = _('CAPI: No commander data returned')
|
||||
|
||||
elif not data.get('commander', {}).get('name'):
|
||||
self.status['text'] = _("Who are you?!") # Shouldn't happen
|
||||
|
||||
elif (not data.get('lastSystem', {}).get('name')
|
||||
or (data['commander'].get('docked')
|
||||
and not data.get('lastStarport', {}).get('name'))): # Only care if docked
|
||||
self.status['text'] = _("Where are you?!") # Shouldn't happen
|
||||
|
||||
elif not data.get('ship', {}).get('name') or not data.get('ship', {}).get('modules'):
|
||||
self.status['text'] = _("What are you flying?!") # Shouldn't happen
|
||||
|
||||
elif monitor.cmdr and data['commander']['name'] != monitor.cmdr:
|
||||
# Companion API return doesn't match Journal
|
||||
raise companion.CmdrError()
|
||||
|
||||
elif ((auto_update and not data['commander'].get('docked'))
|
||||
or (data['lastSystem']['name'] != monitor.system)
|
||||
or ((data['commander']['docked']
|
||||
|
@ -46,6 +46,9 @@
|
||||
/* Folder selection button on Windows. [prefs.py] */
|
||||
"Browse..." = "Browse...";
|
||||
|
||||
/* No 'commander' data in CAPI [EDMarketConnector.py] */
|
||||
"CAPI: No commander data returned" = "CAPI: No commander data returned";
|
||||
|
||||
/* Federation rank. [stats.py] */
|
||||
"Cadet" = "Cadet";
|
||||
|
||||
|
@ -532,6 +532,10 @@ class Session(object):
|
||||
def station(self) -> CAPIData:
|
||||
"""Perform CAPI /profile endpoint query for station data."""
|
||||
data = self.query(URL_QUERY)
|
||||
if 'commander' not in data:
|
||||
logger.error('No commander in returned data')
|
||||
return data
|
||||
|
||||
if not data['commander'].get('docked'):
|
||||
return data
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user