diff --git a/crates/api_common/src/lib.rs b/crates/api_common/src/lib.rs index e924aa809..dca09b97e 100644 --- a/crates/api_common/src/lib.rs +++ b/crates/api_common/src/lib.rs @@ -237,10 +237,9 @@ pub fn is_admin(local_user_view: &LocalUserView) -> Result<(), LemmyError> { } pub async fn get_post(post_id: PostId, pool: &DbPool) -> Result { - match blocking(pool, move |conn| Post::read(conn, post_id)).await? { - Ok(post) => Ok(post), - Err(_e) => Err(ApiError::err("couldnt_find_post").into()), - } + blocking(pool, move |conn| Post::read(conn, post_id)) + .await? + .map_err(|_| ApiError::err("couldnt_find_post").into()) } pub async fn get_local_user_view_from_jwt( diff --git a/crates/api_crud/src/user/create.rs b/crates/api_crud/src/user/create.rs index 96bc3be9a..be9fdbed9 100644 --- a/crates/api_crud/src/user/create.rs +++ b/crates/api_crud/src/user/create.rs @@ -111,16 +111,11 @@ impl PerformCrud for Register { }; // insert the person - let inserted_person = match blocking(context.pool(), move |conn| { + let inserted_person = blocking(context.pool(), move |conn| { Person::create(conn, &person_form) }) .await? - { - Ok(u) => u, - Err(_) => { - return Err(ApiError::err("user_already_exists").into()); - } - }; + .map_err(|_| ApiError::err("user_already_exists"))?; // Create the local user let local_user_form = LocalUserForm {