if do_add {
let like_form2 = like_form.clone();
let like = move |conn: &'_ _| PostLike::like(conn, &like_form2);
- if blocking(context.pool(), like).await?.is_err() {
- return Err(ApiError::err("couldnt_like_post").into());
- }
+ blocking(context.pool(), like)
+ .await?
+ .map_err(|e| ApiError::err("couldnt_like_post", e))?;
Vote::send(
&object,
if data.save {
let save = move |conn: &'_ _| PostSaved::save(conn, &post_saved_form);
- if blocking(context.pool(), save).await?.is_err() {
- return Err(ApiError::err("couldnt_save_post").into());
- }
+ blocking(context.pool(), save)
+ .await?
+ .map_err(|e| ApiError::err("couldnt_save_post", e))?;
} else {
let unsave = move |conn: &'_ _| PostSaved::unsave(conn, &post_saved_form);
- if blocking(context.pool(), unsave).await?.is_err() {
- return Err(ApiError::err("couldnt_save_post").into());
- }
+ blocking(context.pool(), unsave)
+ .await?
+ .map_err(|e| ApiError::err("couldnt_save_post", e))?;
}
let post_id = data.post_id;