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 {
|
Self {
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
inner_client: crate::platform::http_client::ReqwestHttpClient::new(Some(
|
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")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
inner_client: crate::platform::http_client::WHATWGFetchHttpClient::new(),
|
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> {
|
pub async fn fetch(&self, url: &str) -> Result<Vec<u8>, Error> {
|
||||||
let response = self.client.get(url).send().await?;
|
let response = self.client.get(url).send().await?;
|
||||||
if response.status() != StatusCode::OK {
|
match response.error_for_status() {
|
||||||
return Err(Error::Network("response code not 200".to_string()));
|
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