Better handling of errors, not good, but better.

This commit is contained in:
2019-01-17 10:46:46 +01:00
parent b214f9b621
commit a3e515c3a7
11 changed files with 162 additions and 25 deletions

View File

@@ -15,7 +15,7 @@ struct Error {
pub struct Eniro;
impl Probe for Eniro {
fn search(&mut self, ctx: &mut Context, number: &str) {
fn search(&mut self, ctx: &mut Context, number: &str) -> Result<(), ()> {
let body = if let Some(cache) = ctx.cache_get("eniro", &number) {
String::from_utf8(cache.data).unwrap()
} else {
@@ -28,12 +28,13 @@ impl Probe for Eniro {
ctx.cache_set("eniro", &number, body.as_bytes())
.expect("wut?! why not?!");
println!("eniro.se:");
if let Ok(error) = Error::from_html(&body) {
println!("eniro.se:");
println!(" {}", error.message);
Ok(())
} else {
println!(" Failed to find any data");
Err(())
}
}
}