mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-09 11:52:27 +03:00
EDMC: Attempt to handle CAPI exceptions as per EDMarketConnector.py
* Moved most of the exception handling/message output down to the outermost try's except clauses.
This commit is contained in:
parent
9e206d092c
commit
50db6c528a
57
EDMC.py
57
EDMC.py
@ -271,6 +271,7 @@ sys.path: {sys.path}'''
|
|||||||
|
|
||||||
companion.session.login(monitor.cmdr, monitor.is_beta)
|
companion.session.login(monitor.cmdr, monitor.is_beta)
|
||||||
|
|
||||||
|
###################################################################
|
||||||
# Initiate CAPI queries
|
# Initiate CAPI queries
|
||||||
querytime = int(time())
|
querytime = int(time())
|
||||||
companion.session.station(query_time=querytime)
|
companion.session.station(query_time=querytime)
|
||||||
@ -286,6 +287,8 @@ sys.path: {sys.path}'''
|
|||||||
logger.error(f'CAPI requests timed out after {_capi_request_timeout} seconds')
|
logger.error(f'CAPI requests timed out after {_capi_request_timeout} seconds')
|
||||||
sys.exit(EXIT_SERVER)
|
sys.exit(EXIT_SERVER)
|
||||||
|
|
||||||
|
###################################################################
|
||||||
|
|
||||||
# noinspection DuplicatedCode
|
# noinspection DuplicatedCode
|
||||||
if isinstance(capi_response, companion.EDMCCAPIFailedRequest):
|
if isinstance(capi_response, companion.EDMCCAPIFailedRequest):
|
||||||
logger.trace_if('capi.worker', f'Failed Request: {capi_response.message}')
|
logger.trace_if('capi.worker', f'Failed Request: {capi_response.message}')
|
||||||
@ -297,9 +300,7 @@ sys.path: {sys.path}'''
|
|||||||
|
|
||||||
logger.trace_if('capi.worker', 'Answer is not a Failure')
|
logger.trace_if('capi.worker', 'Answer is not a Failure')
|
||||||
if not isinstance(capi_response, companion.EDMCCAPIResponse):
|
if not isinstance(capi_response, companion.EDMCCAPIResponse):
|
||||||
msg = f"Response was neither CAPIFailedRequest nor EDMCAPIResponse: {type(capi_response)}"
|
raise ValueError(f"Response was neither CAPIFailedRequest nor EDMCAPIResponse: {type(capi_response)}")
|
||||||
logger.error(msg)
|
|
||||||
raise ValueError(msg)
|
|
||||||
|
|
||||||
data = capi_response.capi_data
|
data = capi_response.capi_data
|
||||||
config.set('querytime', querytime)
|
config.set('querytime', querytime)
|
||||||
@ -309,10 +310,10 @@ sys.path: {sys.path}'''
|
|||||||
logger.error("No data['command']['name'] from CAPI")
|
logger.error("No data['command']['name'] from CAPI")
|
||||||
sys.exit(EXIT_SERVER)
|
sys.exit(EXIT_SERVER)
|
||||||
|
|
||||||
elif not deep_get(data, 'lastSystem', 'name') or \
|
elif (
|
||||||
data['commander'].get('docked') and not \
|
not deep_get(data, 'lastSystem', 'name') or
|
||||||
deep_get(data, 'lastStarport', 'name'): # Only care if docked
|
data['commander'].get('docked') and not deep_get(data, 'lastStarport', 'name')
|
||||||
|
): # Only care if docked
|
||||||
logger.error("No data['lastSystem']['name'] from CAPI")
|
logger.error("No data['lastSystem']['name'] from CAPI")
|
||||||
sys.exit(EXIT_SERVER)
|
sys.exit(EXIT_SERVER)
|
||||||
|
|
||||||
@ -324,16 +325,15 @@ sys.path: {sys.path}'''
|
|||||||
pass # Skip further validation
|
pass # Skip further validation
|
||||||
|
|
||||||
elif data['commander']['name'] != monitor.cmdr:
|
elif data['commander']['name'] != monitor.cmdr:
|
||||||
logger.error(f'Commander "{data["commander"]["name"]}" from CAPI doesn\'t match "{monitor.cmdr}" from Journal') # noqa: E501
|
raise companion.CmdrError()
|
||||||
sys.exit(EXIT_CREDENTIALS)
|
|
||||||
|
|
||||||
elif data['lastSystem']['name'] != monitor.system or \
|
elif (
|
||||||
((data['commander']['docked'] and data['lastStarport']['name'] or None) != monitor.station) or \
|
data['lastSystem']['name'] != monitor.system or
|
||||||
data['ship']['id'] != monitor.state['ShipID'] or \
|
((data['commander']['docked'] and data['lastStarport']['name'] or None) != monitor.station) or
|
||||||
data['ship']['name'].lower() != monitor.state['ShipType']:
|
data['ship']['id'] != monitor.state['ShipID'] or
|
||||||
|
data['ship']['name'].lower() != monitor.state['ShipType']
|
||||||
logger.error('Mismatch(es) between CAPI and Journal for at least one of: StarSystem, Last Star Port, Ship ID or Ship Name/Type') # noqa: E501
|
):
|
||||||
sys.exit(EXIT_LAGGING)
|
raise companion.ServerLagging()
|
||||||
|
|
||||||
# stuff we can do when not docked
|
# stuff we can do when not docked
|
||||||
if args.d:
|
if args.d:
|
||||||
@ -446,13 +446,36 @@ sys.path: {sys.path}'''
|
|||||||
logger.exception('Failed to send data to EDDN')
|
logger.exception('Failed to send data to EDDN')
|
||||||
|
|
||||||
except companion.ServerError:
|
except companion.ServerError:
|
||||||
logger.error('Frontier CAPI Server returned an error')
|
logger.exception('Frontier CAPI Server returned an error')
|
||||||
|
sys.exit(EXIT_SERVER)
|
||||||
|
|
||||||
|
except companion.ServerConnectionError:
|
||||||
|
logger.exception('Exception while contacting server')
|
||||||
sys.exit(EXIT_SERVER)
|
sys.exit(EXIT_SERVER)
|
||||||
|
|
||||||
except companion.CredentialsError:
|
except companion.CredentialsError:
|
||||||
logger.error('Frontier CAPI Server: Invalid Credentials')
|
logger.error('Frontier CAPI Server: Invalid Credentials')
|
||||||
sys.exit(EXIT_CREDENTIALS)
|
sys.exit(EXIT_CREDENTIALS)
|
||||||
|
|
||||||
|
# Companion API problem
|
||||||
|
except companion.ServerLagging:
|
||||||
|
logger.error(
|
||||||
|
'Mismatch(es) between CAPI and Journal for at least one of: '
|
||||||
|
'StarSystem, Last Star Port, Ship ID or Ship Name/Type'
|
||||||
|
)
|
||||||
|
sys.exit(EXIT_SERVER)
|
||||||
|
|
||||||
|
except companion.CmdrError: # Companion API return doesn't match Journal
|
||||||
|
logger.error(
|
||||||
|
f'Commander "{data["commander"]["name"]}" from CAPI doesn\'t match '
|
||||||
|
f'"{monitor.cmdr}" from Journal'
|
||||||
|
)
|
||||||
|
sys.exit(EXIT_SERVER)
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
logger.exception('"other" exception')
|
||||||
|
sys.exit(EXIT_SERVER)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user