From f29aca941be770f4b1189b4046e0500dfc8614a3 Mon Sep 17 00:00:00 2001 From: daladim Date: Sun, 21 Mar 2021 19:24:31 +0100 Subject: [PATCH] Removed unwraps --- src/client.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/client.rs b/src/client.rs index 14ee71a..ae110f7 100644 --- a/src/client.rs +++ b/src/client.rs @@ -98,9 +98,12 @@ impl Client { async fn sub_request_and_process(&self, url: &Url, body: String, items: &[&str]) -> Result> { let text = self.sub_request(url, body, 0).await?; - let mut current_element: &Element = &text.parse().unwrap(); + let mut current_element: &Element = &text.parse()?; for item in items { - current_element = find_elem(¤t_element, item).unwrap(); + current_element = match find_elem(¤t_element, item) { + Some(elem) => elem, + None => return Err(format!("missing element {}", item).into()), + } } Ok(current_element.text()) } @@ -141,7 +144,7 @@ impl Client { let text = self.sub_request(&cal_home_set, CAL_BODY.into(), 1).await?; - let root: Element = text.parse().unwrap(); + let root: Element = text.parse()?; let reps = find_elems(&root, "response"); let mut calendars = HashMap::new(); for rep in reps {