composer-cli: Handle download errors

The API will return an error 400 with a json error object if the
download fails, catch this and report the error to the user without a
traceback.
This commit is contained in:
Brian C. Lane 2018-03-14 09:53:33 -07:00
parent de604b37a6
commit aa076ee53b
2 changed files with 9 additions and 1 deletions

View File

@ -49,4 +49,8 @@ def main(opts):
log.error("Missing %s sub-command", opts.args[0])
return 1
else:
return command_map[opts.args[0]](opts)
try:
return command_map[opts.args[0]](opts)
except Exception as e:
log.error(str(e))
return 1

View File

@ -158,6 +158,10 @@ def download_file(socket_path, url, progress=True):
"""
http = UnixHTTPConnectionPool(socket_path)
r = http.request("GET", url, preload_content=False)
if r.status == 400:
err = json.loads(r.data.decode("utf-8"))
if not err["status"]:
raise RuntimeError(err["error"]["msg"])
filename = get_filename(r)
if os.path.exists(filename):