Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bubelov committed Oct 12, 2024
1 parent 7fdf291 commit a7f1f92
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/rpc/get_area.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::model::RpcArea;
use crate::{admin, area::Area, Result};
use crate::{admin, area::Area, Error, Result};
use deadpool_sqlite::Pool;
use jsonrpc_v2::{Data, Params};
use serde::Deserialize;
Expand All @@ -15,11 +15,14 @@ pub struct Args {

pub async fn run(Params(args): Params<Args>, pool: Data<Arc<Pool>>) -> Result<RpcArea> {
admin::service::check_rpc(&args.password, NAME, &pool).await?;
let cloned_id = args.id.clone();
let area = pool
.get()
.await?
.interact(move |conn| Area::select_by_id_or_alias(&args.id, conn))
.await??
.unwrap();
Ok(area.into())
.interact(move |conn| Area::select_by_id_or_alias(&cloned_id, conn))
.await??;
area.map(|it| it.into()).ok_or(Error::HttpNotFound(format!(
"There is no area with id or alias = {}",
args.id
)))
}

0 comments on commit a7f1f92

Please sign in to comment.