Some more error handling in the HTTP source

This commit is contained in:
Sebastian Dröge 2016-05-14 17:20:51 +03:00
parent b2b8332043
commit 2298fc3353

View file

@ -84,17 +84,24 @@ impl Source for HttpSrc {
match self.url { match self.url {
None => return false, None => return false,
Some(ref url) => { Some(ref url) => {
let response = self.client.get(url.clone()).send().unwrap(); match self.client.get(url.clone()).send() {
if response.status.is_success() { Ok(response) => {
match response.headers.get::<ContentLength>() { if response.status.is_success() {
Some(&ContentLength(size)) => self.size = size, self.size = match response.headers.get::<ContentLength>() {
_ => self.size = u64::MAX Some(&ContentLength(size)) => size,
_ => u64::MAX
};
self.response = Some(response);
return true;
} else {
println_err!("Failed to fetch {}: {}", url, response.status);
return false;
}
},
Err(err) => {
println_err!("Failed to fetch {}: {}", url, err.to_string());
return false;
} }
self.response = Some(response);
return true;
} else {
println_err!("Failed to fetch {}: {}", url, response.status);
return false;
} }
}, },
} }