]> Untitled Git - lemmy.git/commitdiff
Dont compare db string errors (fixes #1393) (#3424)
authorNutomic <me@nutomic.com>
Mon, 3 Jul 2023 15:59:49 +0000 (17:59 +0200)
committerGitHub <noreply@github.com>
Mon, 3 Jul 2023 15:59:49 +0000 (11:59 -0400)
* Dont compare db string errors (fixes #1393)

* cargo fmt

---------

Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
crates/api_crud/src/post/create.rs
crates/api_crud/src/post/update.rs
crates/utils/src/utils/validation.rs

index 0bbbabcb041ca12644ae7b54eda785d5f65e356f..1dcc90241157fb06564b13e3b79ebf218ae98881 100644 (file)
@@ -107,18 +107,9 @@ impl PerformCrud for CreatePost {
       .thumbnail_url(thumbnail_url)
       .build();
 
-    let inserted_post = match Post::create(context.pool(), &post_form).await {
-      Ok(post) => post,
-      Err(e) => {
-        let err_type = if e.to_string() == "value too long for type character varying(200)" {
-          "post_title_too_long"
-        } else {
-          "couldnt_create_post"
-        };
-
-        return Err(LemmyError::from_error_message(e, err_type));
-      }
-    };
+    let inserted_post = Post::create(context.pool(), &post_form)
+      .await
+      .map_err(|e| LemmyError::from_error_message(e, "couldnt_create_post"))?;
 
     let inserted_post_id = inserted_post.id;
     let protocol_and_hostname = context.settings().get_protocol_and_hostname();
index 253340834b443afa4c5101427acd9de879186ae0..632bc5ae75af78483582a15605a8668ee6bf2c54 100644 (file)
@@ -96,16 +96,9 @@ impl PerformCrud for EditPost {
       .build();
 
     let post_id = data.post_id;
-    let res = Post::update(context.pool(), post_id, &post_form).await;
-    if let Err(e) = res {
-      let err_type = if e.to_string() == "value too long for type character varying(200)" {
-        "post_title_too_long"
-      } else {
-        "couldnt_update_post"
-      };
-
-      return Err(LemmyError::from_error_message(e, err_type));
-    }
+    Post::update(context.pool(), post_id, &post_form)
+      .await
+      .map_err(|e| LemmyError::from_error_message(e, "couldnt_create_post"))?;
 
     build_post_response(
       context,
index 7e09c5af8766929830c75f601e7eccf6aa24d507..347d791a8127f34c2720019572bb45a96e2a7cb1 100644 (file)
@@ -8,7 +8,7 @@ use url::Url;
 static VALID_ACTOR_NAME_REGEX: Lazy<Regex> =
   Lazy::new(|| Regex::new(r"^[a-zA-Z0-9_]{3,}$").expect("compile regex"));
 static VALID_POST_TITLE_REGEX: Lazy<Regex> =
-  Lazy::new(|| Regex::new(r".*\S{3,}.*").expect("compile regex"));
+  Lazy::new(|| Regex::new(r".*\S{3,200}.*").expect("compile regex"));
 static VALID_MATRIX_ID_REGEX: Lazy<Regex> = Lazy::new(|| {
   Regex::new(r"^@[A-Za-z0-9._=-]+:[A-Za-z0-9.-]+\.[A-Za-z]{2,}$").expect("compile regex")
 });