Skip to content

Commit

Permalink
Fix remove unwrap crash
Browse files Browse the repository at this point in the history
  • Loading branch information
cristiancolosimo committed Nov 21, 2023
1 parent 8853218 commit d5964ca
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ async fn fetch_history() -> Option<String> {
return None;
}
let val = current_state_lab_raw.unwrap();
let parsed_resp: Vec<UserHistoryFetch> = val.json::<Vec<UserHistoryFetch>>().await.unwrap();
let parsed_resp: Vec<UserHistoryFetch> = val.json::<Vec<UserHistoryFetch>>().await.unwrap_or(Vec::new());

let first_user = parsed_resp.first();
if first_user.is_none() {
Expand Down Expand Up @@ -212,7 +212,13 @@ async fn fetching_state_loop(pool: &Pool<DbConnectionType>) {
let current_state_lab_raw = reqwest::get(get_lab_state_endpoint).await;
let mut current_state_lab_id: bool = false;
if let Ok(data) = current_state_lab_raw {
let current_state_lab: LabState = data.json().await.unwrap();
let current_state_lab: LabState = match data.json().await{
Ok(data) => data,
Err(err) => {
log::error!("Error parsing json: {:?}", err);
return;
}
}
log::info!("Current state 1: {:?}", current_state_lab);
current_state_lab_id = current_state_lab.id == 1; //Casting int to bool
}
Expand Down

0 comments on commit d5964ca

Please sign in to comment.