Skip to content

Commit 1f16972

Browse files
Fix remove unwrap crash
1 parent 8853218 commit 1f16972

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/main.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ async fn fetch_history() -> Option<String> {
177177
return None;
178178
}
179179
let val = current_state_lab_raw.unwrap();
180-
let parsed_resp: Vec<UserHistoryFetch> = val.json::<Vec<UserHistoryFetch>>().await.unwrap();
180+
let parsed_resp: Vec<UserHistoryFetch> = val.json::<Vec<UserHistoryFetch>>().await.unwrap_or(Vec::new());
181181

182182
let first_user = parsed_resp.first();
183183
if first_user.is_none() {
@@ -212,7 +212,13 @@ async fn fetching_state_loop(pool: &Pool<DbConnectionType>) {
212212
let current_state_lab_raw = reqwest::get(get_lab_state_endpoint).await;
213213
let mut current_state_lab_id: bool = false;
214214
if let Ok(data) = current_state_lab_raw {
215-
let current_state_lab: LabState = data.json().await.unwrap();
215+
let current_state_lab: LabState = match data.json().await{
216+
Ok(data) => data,
217+
Err(err) => {
218+
log::error!("Error parsing json: {:?}", err);
219+
return;
220+
}
221+
}
216222
log::info!("Current state 1: {:?}", current_state_lab);
217223
current_state_lab_id = current_state_lab.id == 1; //Casting int to bool
218224
}

0 commit comments

Comments
 (0)