mirror of
https://github.com/maplibre/maplibre-rs.git
synced 2025-12-08 19:05:57 +00:00
Handle network errors better
This commit is contained in:
parent
2bd1f75b1e
commit
a19f0ddfc1
@ -30,7 +30,7 @@ impl HttpSourceClient {
|
||||
Self {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
inner_client: crate::platform::http_client::ReqwestHttpClient::new(Some(
|
||||
"/tmp/mapr-cache".to_string(), // TODO make path dynamic
|
||||
"./mapr-cache".to_string(), // TODO make path dynamic
|
||||
)),
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
inner_client: crate::platform::http_client::WHATWGFetchHttpClient::new(),
|
||||
|
||||
@ -38,10 +38,16 @@ impl ReqwestHttpClient {
|
||||
|
||||
pub async fn fetch(&self, url: &str) -> Result<Vec<u8>, Error> {
|
||||
let response = self.client.get(url).send().await?;
|
||||
if response.status() != StatusCode::OK {
|
||||
return Err(Error::Network("response code not 200".to_string()));
|
||||
match response.error_for_status() {
|
||||
Ok(response) => {
|
||||
if response.status() == StatusCode::NOT_MODIFIED {
|
||||
log::info!("Using data from cache");
|
||||
}
|
||||
|
||||
let body = response.bytes().await?;
|
||||
Ok(Vec::from(body.as_ref()))
|
||||
}
|
||||
Err(e) => Err(Error::Network(e.to_string())),
|
||||
}
|
||||
let body = response.bytes().await?;
|
||||
Ok(Vec::from(body.as_ref()))
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user