util: Improve error message for failing requests to GH. (#3159)

Piotr Osiewicz and Julia Risley created

Release notes:
- N/A

Co-authored-by: Julia Risley <julia@zed.dev>

Change summary

crates/util/src/github.rs | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

Detailed changes

crates/util/src/github.rs 🔗

@@ -1,5 +1,5 @@
 use crate::http::HttpClient;
-use anyhow::{anyhow, Context, Result};
+use anyhow::{anyhow, bail, Context, Result};
 use futures::AsyncReadExt;
 use serde::Deserialize;
 use std::sync::Arc;
@@ -46,6 +46,14 @@ pub async fn latest_github_release(
         .await
         .context("error reading latest release")?;
 
+    if response.status().is_client_error() {
+        let text = String::from_utf8_lossy(body.as_slice());
+        bail!(
+            "status error {}, response: {text:?}",
+            response.status().as_u16()
+        );
+    }
+
     let releases = match serde_json::from_slice::<Vec<GithubRelease>>(body.as_slice()) {
         Ok(releases) => releases,