From 6f71e41b71b22742a5ced431e2463d4175cc4d53 Mon Sep 17 00:00:00 2001 From: Sakuhl <2012collector@gmail.com> Date: Thu, 25 Jan 2018 19:13:42 +0100 Subject: [PATCH] Improve error handling --- src/main.rs | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3f686b0..f4979da 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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(); }