Files
chatmail-core/src/configure/read_url.rs
Friedel Ziegelmayer 24f4cbbb27 refactor: replace failure
- failure is deprecated
- thiserror for deriving Error impl
- anyhow for highlevel error handling
2020-04-10 22:39:28 +02:00

25 lines
558 B
Rust

use crate::context::Context;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("URL request error")]
GetError(#[from] reqwest::Error),
}
pub fn read_url(context: &Context, url: &str) -> Result<String, Error> {
info!(context, "Requesting URL {}", url);
match reqwest::blocking::Client::new()
.get(url)
.send()
.and_then(|res| res.text())
{
Ok(res) => Ok(res),
Err(err) => {
info!(context, "Can\'t read URL {}", url);
Err(Error::GetError(err))
}
}
}