Update composer-cli for the new error return types.

(cherry picked from commit bc96f75992)
This commit is contained in:
Chris Lumens 2018-08-09 11:53:27 -04:00
parent 05e1a34687
commit 9c188b84a6
2 changed files with 6 additions and 4 deletions

View File

@ -59,7 +59,7 @@ def handle_api_result(result, show_json=False):
:param result: JSON result from the http query :param result: JSON result from the http query
:type result: dict :type result: dict
:rtype: tuple :rtype: tuple
:returns: (rc, errors) :returns: (rc, should_exit_now)
Return the correct rc for the program (0 or 1), and whether or Return the correct rc for the program (0 or 1), and whether or
not to continue processing the results. not to continue processing the results.
@ -68,7 +68,7 @@ def handle_api_result(result, show_json=False):
print(json.dumps(result, indent=4)) print(json.dumps(result, indent=4))
else: else:
for err in result.get("errors", []): for err in result.get("errors", []):
log.error(err) log.error(err["msg"])
# What's the rc? If status is present, use that # What's the rc? If status is present, use that
# If not, use length of errors # If not, use length of errors

View File

@ -50,7 +50,8 @@ def get_url_raw(socket_path, url):
if r.status == 400: if r.status == 400:
err = json.loads(r.data.decode("utf-8")) err = json.loads(r.data.decode("utf-8"))
if "status" in err and err["status"] == False: 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') return r.data.decode('utf-8')
@ -172,7 +173,8 @@ def download_file(socket_path, url, progress=True):
if r.status == 400: if r.status == 400:
err = json.loads(r.data.decode("utf-8")) err = json.loads(r.data.decode("utf-8"))
if not err["status"]: 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) filename = get_filename(r.headers)
if os.path.exists(filename): if os.path.exists(filename):