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:
parent
de604b37a6
commit
aa076ee53b
@ -49,4 +49,8 @@ def main(opts):
|
|||||||
log.error("Missing %s sub-command", opts.args[0])
|
log.error("Missing %s sub-command", opts.args[0])
|
||||||
return 1
|
return 1
|
||||||
else:
|
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
|
||||||
|
@ -158,6 +158,10 @@ def download_file(socket_path, url, progress=True):
|
|||||||
"""
|
"""
|
||||||
http = UnixHTTPConnectionPool(socket_path)
|
http = UnixHTTPConnectionPool(socket_path)
|
||||||
r = http.request("GET", url, preload_content=False)
|
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)
|
filename = get_filename(r)
|
||||||
if os.path.exists(filename):
|
if os.path.exists(filename):
|
||||||
|
Loading…
Reference in New Issue
Block a user