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 d03a198a8c
commit 473ee99eb9
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
: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

View File

@ -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):