1use reqwest;
2use std::io;
3
4pub fn handled_reqwest_errors(uri: &str, e: reqwest::Error) -> io::Error {
6 io::Error::new(
7 io::ErrorKind::ConnectionAborted,
8 format!("[Warning] when connecting to {}\n{}", uri, e.to_string()),
9 )
10}
11
12pub fn get(uri: &str, writer: &mut Vec<u8>) -> Result<(), io::Error> {
15 let mut result = match reqwest::Client::new().get(uri).send() {
16 Ok(res) => res,
17 Err(e) => return Err(handled_reqwest_errors(uri, e)),
18 };
19 if result.status() != 200 {
20 return Err(io::Error::new(
21 io::ErrorKind::ConnectionAborted,
22 format!(
23 "[Warning] when connecting to {}\nResponse Statut : {}",
24 uri,
25 result.status()
26 ),
27 ));
28 }
29 match result.copy_to(writer) {
30 Ok(_) => Ok(()),
31 Err(e) => Err(handled_reqwest_errors(uri, e)),
32 }
33}