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