From 76e4be197818bf1b7a61dbc03ed97418f784ec5a Mon Sep 17 00:00:00 2001 From: Philip Paquette Date: Fri, 23 Aug 2019 10:09:56 -0400 Subject: [API] Logging error if no response.body is returned --- diplomacy/integration/webdiplomacy_net/api.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'diplomacy') diff --git a/diplomacy/integration/webdiplomacy_net/api.py b/diplomacy/integration/webdiplomacy_net/api.py index a12e28a..6ec297c 100644 --- a/diplomacy/integration/webdiplomacy_net/api.py +++ b/diplomacy/integration/webdiplomacy_net/api.py @@ -45,7 +45,7 @@ class API(BaseAPI): return_val = [] # 200 - Response OK - if response.code == 200: + if response.code == 200 and response.body: list_games_players = json.loads(response.body.decode('utf-8')) for game_player in list_games_players: return_val += [GameIdCountryId(game_id=game_player['gameID'], country_id=game_player['countryID'])] @@ -68,7 +68,7 @@ class API(BaseAPI): return_val = [] # 200 - Response OK - if response.code == 200: + if response.code == 200 and response.body: list_games_players = json.loads(response.body.decode('utf-8')) for game_player in list_games_players: return_val += [GameIdCountryId(game_id=game_player['gameID'], country_id=game_player['countryID'])] @@ -96,7 +96,7 @@ class API(BaseAPI): return_val = None, None # 200 - Response OK - if response.code == 200: + if response.code == 200 and response.body: state_dict = json.loads(response.body.decode('utf-8')) game, power_name = state_dict_to_game_and_power(state_dict, country_id, max_phases=max_phases) return_val = game, power_name @@ -168,6 +168,11 @@ class API(BaseAPI): if not orders: return True + # No response received from the server - Maybe a connection timeout? + if not response.body: + LOGGER.warning('WARNING during "%s". No response body received. Is the server OK?', route) + return False + # Otherwise, validating that received orders are the same as submitted orders response_body = json.loads(response.body) orders_dict = [Order(order, map_name=game.map_name, phase_type=game.phase_type) for order in response_body] -- cgit v1.2.3