Fix composer-cli handling of log and detail errors.

This commit is contained in:
Brian C. Lane 2018-03-22 16:15:01 -07:00
parent 2481c486a5
commit 423e8cba88
2 changed files with 14 additions and 1 deletions

View File

@ -215,9 +215,14 @@ def compose_log(socket_path, api_version, args, show_json=False, testmode=0):
log_size = 1024
api_route = client.api_url(api_version, "/compose/log/%s?size=%d" % (args[0], log_size))
result = client.get_url_raw(socket_path, api_route)
try:
result = client.get_url_raw(socket_path, api_route)
except RuntimeError as e:
print(str(e))
return 1
print(result)
return 0
def compose_cancel(socket_path, api_version, args, show_json=False, testmode=0):
"""Cancel a running compose
@ -311,6 +316,9 @@ def compose_details(socket_path, api_version, args, show_json=False, testmode=0)
if show_json:
print(json.dumps(result, indent=4))
return 0
if "status" in result:
print(result["error"]["msg"])
return 1
print("%s %-8s %-15s %s %s" % (result["id"],
result["queue_status"],

View File

@ -47,6 +47,11 @@ def get_url_raw(socket_path, url):
"""
http = UnixHTTPConnectionPool(socket_path)
r = http.request("GET", url)
if r.status == 400:
err = json.loads(r.data.decode("utf-8"))
if "status" in err and err["status"] == False:
raise RuntimeError(err["error"]["msg"])
return r.data.decode('utf-8')
def get_url_json(socket_path, url):