Improve database errors (NotFound -> Option)

This commit is contained in:
Tobias Reisinger 2023-11-27 13:33:04 +01:00
parent be7f31906c
commit 8dab4b9a50
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
9 changed files with 96 additions and 78 deletions
emgauwa-controller/src

View file

@ -2,7 +2,6 @@ use std::str;
use crate::relay_loop::run_relay_loop;
use crate::settings::Settings;
use emgauwa_lib::db::errors::DatabaseError;
use emgauwa_lib::db::{DbController, DbRelay};
use emgauwa_lib::types::ControllerUid;
use emgauwa_lib::{db, models};
@ -75,14 +74,10 @@ async fn main() {
relay.number.unwrap(),
)
.await
.expect("Failed to get relay from database")
{
Ok(relay) => relay,
Err(err) => match err {
DatabaseError::NotFound => {
create_this_relay(&mut conn, &db_controller, relay).await
}
_ => panic!("Failed to get relay from database"),
},
None => create_this_relay(&mut conn, &db_controller, relay).await,
Some(relay) => relay,
}
})
})