]> Untitled Git - lemmy.git/blobdiff - crates/api_crud/src/comment/create.rs
Dont swallow API errors (fixes #1834) (#1837)
[lemmy.git] / crates / api_crud / src / comment / create.rs
index c357e60474827dde2641f941ea2a5771fd579181..674914629a6f0b483eb0f202c85a5f109b7f2273 100644 (file)
@@ -61,7 +61,7 @@ impl PerformCrud for CreateComment {
 
     // Check if post is locked, no new comments
     if post.locked {
-      return Err(ApiError::err("locked").into());
+      return Err(ApiError::err_plain("locked").into());
     }
 
     // If there's a parent_id, check to make sure that comment is in that post
@@ -69,13 +69,13 @@ impl PerformCrud for CreateComment {
       // Make sure the parent comment exists
       let parent = blocking(context.pool(), move |conn| Comment::read(conn, parent_id))
         .await?
-        .map_err(|_| ApiError::err("couldnt_create_comment"))?;
+        .map_err(|e| ApiError::err("couldnt_create_comment", e))?;
 
       check_person_block(local_user_view.person.id, parent.creator_id, context.pool()).await?;
 
       // Strange issue where sometimes the post ID is incorrect
       if parent.post_id != post_id {
-        return Err(ApiError::err("couldnt_create_comment").into());
+        return Err(ApiError::err_plain("couldnt_create_comment").into());
       }
     }
 
@@ -93,7 +93,7 @@ impl PerformCrud for CreateComment {
       Comment::create(conn, &comment_form2)
     })
     .await?
-    .map_err(|_| ApiError::err("couldnt_create_comment"))?;
+    .map_err(|e| ApiError::err("couldnt_create_comment", e))?;
 
     // Necessary to update the ap_id
     let inserted_comment_id = inserted_comment.id;
@@ -109,7 +109,7 @@ impl PerformCrud for CreateComment {
         Ok(Comment::update_ap_id(conn, inserted_comment_id, apub_id)?)
       })
       .await?
-      .map_err(|_| ApiError::err("couldnt_create_comment"))?;
+      .map_err(|e| ApiError::err("couldnt_create_comment", e))?;
 
     CreateOrUpdateComment::send(
       &updated_comment,
@@ -142,9 +142,9 @@ impl PerformCrud for CreateComment {
     };
 
     let like = move |conn: &'_ _| CommentLike::like(conn, &like_form);
-    if blocking(context.pool(), like).await?.is_err() {
-      return Err(ApiError::err("couldnt_like_comment").into());
-    }
+    blocking(context.pool(), like)
+      .await?
+      .map_err(|e| ApiError::err("couldnt_like_comment", e))?;
 
     let object = PostOrComment::Comment(updated_comment);
     Vote::send(
@@ -170,7 +170,7 @@ impl PerformCrud for CreateComment {
         Comment::update_read(conn, comment_id, true)
       })
       .await?
-      .map_err(|_| ApiError::err("couldnt_update_comment"))?;
+      .map_err(|e| ApiError::err("couldnt_update_comment", e))?;
     }
     // If its a reply, mark the parent as read
     if let Some(parent_id) = data.parent_id {
@@ -183,7 +183,7 @@ impl PerformCrud for CreateComment {
           Comment::update_read(conn, parent_id, true)
         })
         .await?
-        .map_err(|_| ApiError::err("couldnt_update_parent_comment"))?;
+        .map_err(|e| ApiError::err("couldnt_update_parent_comment", e))?;
       }
       // If the parent has PersonMentions mark them as read too
       let person_id = local_user_view.person.id;
@@ -196,7 +196,7 @@ impl PerformCrud for CreateComment {
           PersonMention::update_read(conn, mention.id, true)
         })
         .await?
-        .map_err(|_| ApiError::err("couldnt_update_person_mentions"))?;
+        .map_err(|e| ApiError::err("couldnt_update_person_mentions", e))?;
       }
     }