Improve database errors (NotFound -> Option)
This commit is contained in:
parent
be7f31906c
commit
8dab4b9a50
9 changed files with 96 additions and 78 deletions
emgauwa-controller/src
|
@ -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,
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue