From 473ee99eb986406f1a1cc8a2204f6a3619afcd9a Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Thu, 9 Aug 2018 11:53:27 -0400 Subject: [PATCH] Update composer-cli for the new error return types. (cherry picked from commit bc96f759927755e9568dc5a9cf39cc75b478bd4a) --- src/composer/cli/utilities.py | 4 ++-- src/composer/http_client.py | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/composer/cli/utilities.py b/src/composer/cli/utilities.py index 97f348e0..199ed095 100644 --- a/src/composer/cli/utilities.py +++ b/src/composer/cli/utilities.py @@ -59,7 +59,7 @@ def handle_api_result(result, show_json=False): :param result: JSON result from the http query :type result: dict :rtype: tuple - :returns: (rc, errors) + :returns: (rc, should_exit_now) Return the correct rc for the program (0 or 1), and whether or not to continue processing the results. @@ -68,7 +68,7 @@ def handle_api_result(result, show_json=False): print(json.dumps(result, indent=4)) else: for err in result.get("errors", []): - log.error(err) + log.error(err["msg"]) # What's the rc? If status is present, use that # If not, use length of errors diff --git a/src/composer/http_client.py b/src/composer/http_client.py index 66970d39..ebbac2af 100644 --- a/src/composer/http_client.py +++ b/src/composer/http_client.py @@ -50,7 +50,8 @@ def get_url_raw(socket_path, url): if r.status == 400: err = json.loads(r.data.decode("utf-8")) if "status" in err and err["status"] == False: - raise RuntimeError(", ".join(err["errors"])) + msgs = [e["msg"] for e in err["errors"]] + raise RuntimeError(", ".join(msgs)) return r.data.decode('utf-8') @@ -172,7 +173,8 @@ def download_file(socket_path, url, progress=True): if r.status == 400: err = json.loads(r.data.decode("utf-8")) if not err["status"]: - raise RuntimeError(", ".join(err["errors"])) + msgs = [e["msg"] for e in err["errors"]] + raise RuntimeError(", ".join(msgs)) filename = get_filename(r.headers) if os.path.exists(filename):