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

Release notes:
- N/A

Co-authored-by: Julia Risley <julia@zed.dev>
This commit is contained in:
Piotr Osiewicz
2023-10-26 10:39:45 +02:00
committed by GitHub
co-authored by Julia Risley
parent 1ec6638c7f
commit bc3572f80e
+9 -1
View File
@@ -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,