From 612a0658d2793aa56e0ba4a23fb39bdea5a8fdfc Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Tue, 17 Oct 2023 08:18:31 -0700 Subject: [PATCH] Improve error message when querying FlakeHub fails --- src/cli/cmd/add/mod.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/cli/cmd/add/mod.rs b/src/cli/cmd/add/mod.rs index 9508f080..55705470 100644 --- a/src/cli/cmd/add/mod.rs +++ b/src/cli/cmd/add/mod.rs @@ -230,11 +230,12 @@ pub(crate) async fn get_flakehub_project_and_url( let res = client.get(&flakehub_json_url.to_string()).send().await?; - if res.status().is_success() { - let res = res.json::().await?; + if let Err(e) = res.error_for_status_ref() { + let err_text = res.text().await?; + return Err(e).wrap_err(err_text)?; + }; - Ok((res.project, res.pretty_download_url)) - } else { - Err(color_eyre::eyre::eyre!(res.text().await?)) - } + let res = res.json::().await?; + + Ok((res.project, res.pretty_download_url)) }