aboutsummaryrefslogtreecommitdiff
path: root/diplomacy
diff options
context:
space:
mode:
authorPhilip Paquette <pcpaquette@gmail.com>2019-08-23 10:09:56 -0400
committerPhilip Paquette <pcpaquette@gmail.com>2019-08-23 21:19:35 -0400
commit76e4be197818bf1b7a61dbc03ed97418f784ec5a (patch)
tree0efca3146fa56c8a84dec3c6da306afacce090f2 /diplomacy
parent63e79a4e0e1db39bb54af22c849756d7fd7b9f57 (diff)
[API] Logging error if no response.body is returned
Diffstat (limited to 'diplomacy')
-rw-r--r--diplomacy/integration/webdiplomacy_net/api.py11
1 files changed, 8 insertions, 3 deletions
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]