Fail gracefully if invalid query

This commit is contained in:
RunasSudo 2019-01-01 15:26:02 +11:00
parent 312bb82a2b
commit 47da751b1b
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A

View File

@ -112,6 +112,10 @@ def latest():
departures = do_request('/v3/departures/route_type/{}/stop/{}'.format(ROUTE_TYPE, flask.request.args['stop_id']), {'platform_numbers': flask.request.args['plat_id'], 'max_results': '5', 'expand': 'all'}) departures = do_request('/v3/departures/route_type/{}/stop/{}'.format(ROUTE_TYPE, flask.request.args['stop_id']), {'platform_numbers': flask.request.args['plat_id'], 'max_results': '5', 'expand': 'all'})
departures['departures'].sort(key=lambda x: x['scheduled_departure_utc']) departures['departures'].sort(key=lambda x: x['scheduled_departure_utc'])
if len(departures['departures']) == 0:
# Invalid stop ID, platform ID, no departures, etc.
return flask.jsonify(result)
result['stop_name'] = departures['stops'][flask.request.args['stop_id']]['stop_name'].replace(' Station', '') result['stop_name'] = departures['stops'][flask.request.args['stop_id']]['stop_name'].replace(' Station', '')
# Next train # Next train