From 00e2a589916894e20051938fc20e886fa57cda14 Mon Sep 17 00:00:00 2001 From: kulisak12 Date: Sun, 18 Sep 2022 14:46:58 +0200 Subject: [PATCH] =?UTF-8?q?Strategick=C3=A1:=20Fix=20error=20hl=C3=A1?= =?UTF-8?q?=C5=A1ek?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- klient/client.py | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/klient/client.py b/klient/client.py index 65bbba2..a64ddba 100644 --- a/klient/client.py +++ b/klient/client.py @@ -111,7 +111,6 @@ def get_state(min_round: int, args) -> dict: logger.warning(f"Request error: {e}") return None, TIME_BEFORE_RETRY if not res.ok: - logger.error(f"Server error: {res.status_code} {res.reason}") log_server_error(res) sys.exit(1) @@ -161,23 +160,20 @@ def send_turn(turn: dict, round: int, args) -> None: # print errors # because such errors are caused by the submitted turn, # retrying will not help, so return True - response = res.json() - if response["status"] == "ok": + res_json = res.json() + if res_json["status"] == "ok": logger.info("Turn accepted.") - elif response["status"] == "too_late": + elif res_json["status"] == "too_late": logger.error("Turn submitted too late.") - elif response["status"] == "error": - logger.error(f"Turn error: {response['description']}") - elif response["status"] == "warning": - member_warns = [ + elif res_json["status"] == "error": + logger.error(f"Turn error: {res_json['description']}") + elif res_json["status"] == "warning": + member_warns = "\n".join([ f" {member['id']}: {member['description']}" - for member in response["members"] - ] + for member in res_json["members"] + ]) logger.info("Turn accepted with warnings.") - logger.warning( - "Member warnings:\n" - "\n".join(member_warns) - ) + logger.warning(f"Member warnings:\n{member_warns}") return True 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: + res_json = res.json() logger.error( - f"Server error: {res.status_code} {res.reason}\n" - f"{res['description']}" + f"Server error: {res.status_code} {res.reason}: " + f"{res_json['description']}" )