From b729c050f99fab760155bbe45b21b30afa5d0349 Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Fri, 27 Oct 2023 01:42:54 +0100 Subject: [PATCH] fix: better error handling --- src/bin/update_data.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/bin/update_data.rs b/src/bin/update_data.rs index a637020..8bb25f4 100644 --- a/src/bin/update_data.rs +++ b/src/bin/update_data.rs @@ -139,19 +139,18 @@ async fn get_wolves(config: &Config) -> Vec { } // get wolves data - let uri = &config.wolves_url; - let mut res = surf::post(uri).header("X-AM-Identity", &config.wolves_key).await.unwrap(); + if let Ok(mut res) = surf::post(&config.wolves_url).header("X-AM-Identity", &config.wolves_key).await { + if let Ok(WolvesResult { + success, + result, + }) = res.body_json().await + { + if success != 1 { + return vec![]; + } - if let Ok(WolvesResult { - success, - result, - }) = res.body_json().await - { - if success != 1 { - return vec![]; + return result.iter().map(AccountWolves::from).collect::>(); } - - return result.iter().map(AccountWolves::from).collect::>(); } vec![]