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,12 +84,13 @@ 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() {
Ok(response) => {
if response.status.is_success() { if response.status.is_success() {
match response.headers.get::<ContentLength>() { self.size = match response.headers.get::<ContentLength>() {
Some(&ContentLength(size)) => self.size = size, Some(&ContentLength(size)) => size,
_ => self.size = u64::MAX _ => u64::MAX
} };
self.response = Some(response); self.response = Some(response);
return true; return true;
} else { } else {
@ -97,6 +98,12 @@ impl Source for HttpSrc {
return false; return false;
} }
}, },
Err(err) => {
println_err!("Failed to fetch {}: {}", url, err.to_string());
return false;
}
}
},
} }
} }