Improve error handling

This commit is contained in:
Sakuhl 2018-01-25 19:13:42 +01:00
parent 42b2f3ff7b
commit 6f71e41b71

View File

@ -39,29 +39,30 @@ fn main() {
}) })
.unwrap(); .unwrap();
let guild_list = wynncraft::guild_list().unwrap(); if let Ok(guild_list) = wynncraft::guild_list() {
let conn = establish_connection(); let conn = establish_connection();
guild_list.into_iter().for_each(|name| { guild_list.into_iter().for_each(|name| {
thread::sleep_ms(2500); thread::sleep_ms(2500);
println!("Getting {:?}", name); println!("Getting {:?}", name);
if let Ok(Some(prefix)) = wynncraft::guild(&name).map(|x| x.map(|x| x.prefix)) { if let Ok(Some(prefix)) = wynncraft::guild(&name).map(|x| x.map(|x| x.prefix)) {
let guild = Guild { prefix: prefix.trim().to_owned(), name }; let guild = Guild { prefix: prefix.trim().to_owned(), name };
if let Ok(_) = diesel::insert_into(guilds::table) if let Ok(_) = diesel::insert_into(guilds::table)
.values(&guild) .values(&guild)
.on_conflict(guilds::prefix) .on_conflict(guilds::prefix)
.do_nothing() .do_nothing()
.execute(&conn) { .execute(&conn) {
let _ = reqwest::get("https://wynnapi.herokuapp.com/").unwrap(); let _ = reqwest::get("https://wynnapi.herokuapp.com/").unwrap();
} else {
println!("Fail!");
}
} else { } else {
println!("Fail!"); println!("Fail!");
} }
} else { });
println!("Fail!");
}
});
println!("Guilds updated!"); println!("Guilds updated!");
}
server_handle.join().unwrap(); server_handle.join().unwrap();
} }