fix(image): http provider not handling non-success codes

This commit is contained in:
Jake Stanger
2023-04-10 20:05:13 +01:00
parent c214f65ecb
commit 7355db74ec

View File

@@ -193,7 +193,16 @@ impl<'a> ImageProvider<'a> {
/// Attempts to get `Bytes` from an HTTP resource asynchronously.
#[cfg(feature = "http")]
async fn get_bytes_from_http(url: reqwest::Url) -> Result<glib::Bytes> {
let bytes = reqwest::get(url).await?.bytes().await?;
Ok(glib::Bytes::from_owned(bytes))
let res = reqwest::get(url).await?;
let status = res.status();
if status.is_success() {
let bytes = res.bytes().await?;
Ok(glib::Bytes::from_owned(bytes))
} else {
Err(Report::msg(format!(
"Received non-success HTTP code ({status})"
)))
}
}
}