diff options
author | Tristan Sloughter <t@crashfast.com> | 2015-10-26 09:53:48 -0500 |
---|---|---|
committer | Tristan Sloughter <t@crashfast.com> | 2015-10-26 09:53:48 -0500 |
commit | d6ea1e7df47653936953e2567c90f674883fb8f1 (patch) | |
tree | 5f65ababc80fd2df8a07b197a9f73c72440086b9 /src | |
parent | 97ae8d659555367df039fc3571fb325bdfc423a6 (diff) |
return more useful error message (failed to download) when pkg http req fails
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar_prv_update.erl | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl index 0491535..6637ebe 100644 --- a/src/rebar_prv_update.erl +++ b/src/rebar_prv_update.erl @@ -44,24 +44,28 @@ do(State) -> TmpFile = filename:join(TmpDir, "packages.gz"), Url = rebar_state:get(State, rebar_packages_cdn, ?DEFAULT_HEX_REGISTRY), - {ok, _RequestId} = httpc:request(get, {Url, []}, - [], [{stream, TmpFile}, {sync, true}], - rebar), - {ok, Data} = file:read_file(TmpFile), - Unzipped = zlib:gunzip(Data), - ok = file:write_file(HexFile, Unzipped), - ?INFO("Writing registry to ~s", [HexFile]), - hex_to_index(State), - ok + case httpc:request(get, {Url, []}, + [], [{stream, TmpFile}, {sync, true}], + rebar) of + {ok, saved_to_file} -> + {ok, Data} = file:read_file(TmpFile), + Unzipped = zlib:gunzip(Data), + ok = file:write_file(HexFile, Unzipped), + ?INFO("Writing registry to ~s", [HexFile]), + hex_to_index(State), + {ok, State}; + _ -> + ?PRV_ERROR(package_index_download) + end catch _E:C -> ?DEBUG("Error creating package index: ~p ~p", [C, erlang:get_stacktrace()]), throw(?PRV_ERROR(package_index_write)) - end, - - {ok, State}. + end. -spec format_error(any()) -> iolist(). +format_error(package_index_download) -> + "Failed to download package index."; format_error(package_index_write) -> "Failed to write package index.". |