Browse Source

Strategická: Fix error hlášek

master
David Klement 2 years ago
parent
commit
00e2a58991
  1. 29
      klient/client.py

29
klient/client.py

@ -111,7 +111,6 @@ def get_state(min_round: int, args) -> dict:
logger.warning(f"Request error: {e}") logger.warning(f"Request error: {e}")
return None, TIME_BEFORE_RETRY return None, TIME_BEFORE_RETRY
if not res.ok: if not res.ok:
logger.error(f"Server error: {res.status_code} {res.reason}")
log_server_error(res) log_server_error(res)
sys.exit(1) sys.exit(1)
@ -161,23 +160,20 @@ def send_turn(turn: dict, round: int, args) -> None:
# print errors # print errors
# because such errors are caused by the submitted turn, # because such errors are caused by the submitted turn,
# retrying will not help, so return True # retrying will not help, so return True
response = res.json() res_json = res.json()
if response["status"] == "ok": if res_json["status"] == "ok":
logger.info("Turn accepted.") logger.info("Turn accepted.")
elif response["status"] == "too_late": elif res_json["status"] == "too_late":
logger.error("Turn submitted too late.") logger.error("Turn submitted too late.")
elif response["status"] == "error": elif res_json["status"] == "error":
logger.error(f"Turn error: {response['description']}") logger.error(f"Turn error: {res_json['description']}")
elif response["status"] == "warning": elif res_json["status"] == "warning":
member_warns = [ member_warns = "\n".join([
f" {member['id']}: {member['description']}" f" {member['id']}: {member['description']}"
for member in response["members"] for member in res_json["members"]
] ])
logger.info("Turn accepted with warnings.") logger.info("Turn accepted with warnings.")
logger.warning( logger.warning(f"Member warnings:\n{member_warns}")
"Member warnings:\n"
"\n".join(member_warns)
)
return True return True
while not send_turn_once(): while not send_turn_once():
@ -185,9 +181,10 @@ def send_turn(turn: dict, round: int, args) -> None:
def log_server_error(res: requests.Response) -> None: def log_server_error(res: requests.Response) -> None:
res_json = res.json()
logger.error( logger.error(
f"Server error: {res.status_code} {res.reason}\n" f"Server error: {res.status_code} {res.reason}: "
f"{res['description']}" f"{res_json['description']}"
) )

Loading…
Cancel
Save