Cache: Return error if HTTP client cannot be created (#247)

Apparently `Client::new` can panic (see #244), so let's return the error instead.
This commit is contained in:
Danilo Bargen 2022-01-08 22:01:36 +01:00 committed by GitHub
commit 84277cc31e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -153,7 +153,9 @@ impl Cache {
builder = builder.proxy(proxy);
}
}
let client = builder.build().unwrap_or_else(|_| Client::new());
let client = builder.build().map_err(|e| {
TealdeerError::UpdateError(format!("Could not instantiate HTTP client: {}", e))
})?;
let mut resp = client.get(&self.url).send()?;
let mut buf: Vec<u8> = vec![];
let bytes_downloaded = resp.copy_to(&mut buf)?;