From 5329b51f0361d6d1386f57c1d374cc07203083ce Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 26 Jan 2023 15:03:34 +0200 Subject: [PATCH 1/3] error handling --- multiversx_sdk_cli/contract_verification.py | 30 ++++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/multiversx_sdk_cli/contract_verification.py b/multiversx_sdk_cli/contract_verification.py index eac612ad..cdaa7a73 100644 --- a/multiversx_sdk_cli/contract_verification.py +++ b/multiversx_sdk_cli/contract_verification.py @@ -79,19 +79,29 @@ def trigger_contract_verification( request_dictionary = contract_verification.to_dictionary() url = f"{verifier_url}/verifier" - response = requests.post(url, json=request_dictionary).json() + response = requests.post(url, json=request_dictionary) - status = response.get("status", "") - if status: - logger.info(f"Task status: {status}") + if response.status_code == 408: + task_id = response.json().get("taskId", "") - if status == "error": - dump_out_json(response) + if task_id: + query_status_with_task_id(verifier_url, task_id) else: - dump_out_json(response) - else: - task_id = response.get("taskId", "") - query_status_with_task_id(verifier_url, task_id) + dump_out_json(response.json()) + elif response.status_code != 200: + dump_out_json(response.json()) + elif response.status_code == 200: + status = response.json().get("status", "") + if status: + logger.info(f"Task status: {status}") + + if status == "error": + dump_out_json(response.json()) + else: + dump_out_json(response.json()) + else: + task_id = response.json().get("taskId", "") + query_status_with_task_id(verifier_url, task_id) def query_status_with_task_id(url: str, task_id: str, interval: int = 10): From 291ac1d1ed863f12439b8275e8d003f9cd91d270 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 26 Jan 2023 16:03:38 +0200 Subject: [PATCH 2/3] fix after review --- multiversx_sdk_cli/contract_verification.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/multiversx_sdk_cli/contract_verification.py b/multiversx_sdk_cli/contract_verification.py index cdaa7a73..df121100 100644 --- a/multiversx_sdk_cli/contract_verification.py +++ b/multiversx_sdk_cli/contract_verification.py @@ -11,6 +11,9 @@ from nacl.signing import SigningKey import requests +HTTP_REQUEST_TIMEOUT = 408 +HTTP_SUCCESS = 200 + logger = logging.getLogger("cli.contracts.verifier") class ContractVerificationRequest: @@ -81,24 +84,20 @@ def trigger_contract_verification( url = f"{verifier_url}/verifier" response = requests.post(url, json=request_dictionary) - if response.status_code == 408: + if response.status_code == HTTP_REQUEST_TIMEOUT: task_id = response.json().get("taskId", "") if task_id: query_status_with_task_id(verifier_url, task_id) else: dump_out_json(response.json()) - elif response.status_code != 200: + elif response.status_code != HTTP_SUCCESS: dump_out_json(response.json()) - elif response.status_code == 200: + elif response.status_code == HTTP_SUCCESS: status = response.json().get("status", "") if status: logger.info(f"Task status: {status}") - - if status == "error": - dump_out_json(response.json()) - else: - dump_out_json(response.json()) + dump_out_json(response.json()) else: task_id = response.json().get("taskId", "") query_status_with_task_id(verifier_url, task_id) From 1b10d82736f4508a4a8d106e806a3bb5bd59af29 Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Thu, 26 Jan 2023 16:03:49 +0200 Subject: [PATCH 3/3] version bump --- multiversx_sdk_cli/_version.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/multiversx_sdk_cli/_version.py b/multiversx_sdk_cli/_version.py index 98886d26..15cf1350 100644 --- a/multiversx_sdk_cli/_version.py +++ b/multiversx_sdk_cli/_version.py @@ -1 +1 @@ -__version__ = "5.2.1" +__version__ = "5.2.2" diff --git a/setup.py b/setup.py index ab2d5193..949256fa 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ import setuptools -VERSION = "5.2.1" +VERSION = "5.2.2" try: with open('./multiversx_sdk_cli/_version.py', 'wt') as versionfile: