diff --git a/server/Cargo.lock b/server/Cargo.lock index 305af342b..023a3f9dd 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -1800,7 +1800,6 @@ version = "0.1.0" dependencies = [ "lemmy_db", "serde 1.0.114", - "thiserror", ] [[package]] @@ -1827,7 +1826,6 @@ version = "0.1.0" dependencies = [ "actix-web", "futures", - "lemmy_api_structs", "lemmy_utils", "log", "strum", @@ -1904,6 +1902,7 @@ dependencies = [ "regex", "serde 1.0.114", "serde_json", + "thiserror", "url", ] diff --git a/server/lemmy_api_structs/Cargo.toml b/server/lemmy_api_structs/Cargo.toml index 93653fba2..3778422be 100644 --- a/server/lemmy_api_structs/Cargo.toml +++ b/server/lemmy_api_structs/Cargo.toml @@ -11,4 +11,3 @@ path = "src/lib.rs" [dependencies] lemmy_db = { path = "../lemmy_db" } serde = { version = "1.0.105", features = ["derive"] } -thiserror = "1.0.20" diff --git a/server/lemmy_api_structs/src/lib.rs b/server/lemmy_api_structs/src/lib.rs index 66abcf200..b3576a0d6 100644 --- a/server/lemmy_api_structs/src/lib.rs +++ b/server/lemmy_api_structs/src/lib.rs @@ -1,24 +1,7 @@ extern crate serde; -extern crate thiserror; pub mod comment; pub mod community; pub mod post; pub mod site; pub mod user; - -use thiserror::Error; - -#[derive(Debug, Error)] -#[error("{{\"error\":\"{message}\"}}")] -pub struct APIError { - pub message: String, -} - -impl APIError { - pub fn err(msg: &str) -> Self { - APIError { - message: msg.to_string(), - } - } -} diff --git a/server/lemmy_rate_limit/Cargo.toml b/server/lemmy_rate_limit/Cargo.toml index 001297fcc..949f72f99 100644 --- a/server/lemmy_rate_limit/Cargo.toml +++ b/server/lemmy_rate_limit/Cargo.toml @@ -10,7 +10,6 @@ path = "src/lib.rs" [dependencies] lemmy_utils = { path = "../lemmy_utils" } -lemmy_api_structs = { path = "../lemmy_api_structs" } tokio = "0.2.21" strum = "0.18.0" strum_macros = "0.18.0" diff --git a/server/lemmy_rate_limit/src/rate_limiter.rs b/server/lemmy_rate_limit/src/rate_limiter.rs index b48547290..1c355acf3 100644 --- a/server/lemmy_rate_limit/src/rate_limiter.rs +++ b/server/lemmy_rate_limit/src/rate_limiter.rs @@ -1,5 +1,4 @@ -use lemmy_api_structs::APIError; -use lemmy_utils::{IPAddr, LemmyError}; +use lemmy_utils::{APIError, IPAddr, LemmyError}; use log::debug; use std::{collections::HashMap, time::SystemTime}; use strum::IntoEnumIterator; diff --git a/server/lemmy_utils/Cargo.toml b/server/lemmy_utils/Cargo.toml index d0806e293..a852cb852 100644 --- a/server/lemmy_utils/Cargo.toml +++ b/server/lemmy_utils/Cargo.toml @@ -20,6 +20,7 @@ itertools = "0.9.0" rand = "0.7.3" serde = { version = "1.0.105", features = ["derive"] } serde_json = { version = "1.0.52", features = ["preserve_order"]} +thiserror = "1.0.20" comrak = "0.7" lazy_static = "1.3.0" openssl = "0.10" diff --git a/server/lemmy_utils/src/lib.rs b/server/lemmy_utils/src/lib.rs index c27033ca5..d28218282 100644 --- a/server/lemmy_utils/src/lib.rs +++ b/server/lemmy_utils/src/lib.rs @@ -9,6 +9,7 @@ extern crate openssl; extern crate rand; extern crate regex; extern crate serde_json; +extern crate thiserror; extern crate url; pub mod settings; @@ -32,6 +33,7 @@ use openssl::{pkey::PKey, rsa::Rsa}; use rand::{distributions::Alphanumeric, thread_rng, Rng}; use regex::{Regex, RegexBuilder}; use std::io::{Error, ErrorKind}; +use thiserror::Error; use url::Url; pub type ConnectionId = usize; @@ -52,6 +54,20 @@ macro_rules! location_info { }; } +#[derive(Debug, Error)] +#[error("{{\"error\":\"{message}\"}}")] +pub struct APIError { + pub message: String, +} + +impl APIError { + pub fn err(msg: &str) -> Self { + APIError { + message: msg.to_string(), + } + } +} + #[derive(Debug)] pub struct LemmyError { inner: anyhow::Error, diff --git a/server/src/api/comment.rs b/server/src/api/comment.rs index 9ad52108b..f0e56810e 100644 --- a/server/src/api/comment.rs +++ b/server/src/api/comment.rs @@ -17,7 +17,7 @@ use crate::{ LemmyContext, }; use actix_web::web::Data; -use lemmy_api_structs::{comment::*, APIError}; +use lemmy_api_structs::comment::*; use lemmy_db::{ comment::*, comment_view::*, @@ -38,6 +38,7 @@ use lemmy_utils::{ scrape_text_for_mentions, send_email, settings::Settings, + APIError, ConnectionId, EndpointType, LemmyError, diff --git a/server/src/api/community.rs b/server/src/api/community.rs index 17eb1c5c8..6fb67b330 100644 --- a/server/src/api/community.rs +++ b/server/src/api/community.rs @@ -18,7 +18,7 @@ use crate::{ }; use actix_web::web::Data; use anyhow::Context; -use lemmy_api_structs::{community::*, APIError}; +use lemmy_api_structs::community::*; use lemmy_db::{ comment::Comment, comment_view::CommentQueryBuilder, @@ -42,6 +42,7 @@ use lemmy_utils::{ location_info, make_apub_endpoint, naive_from_unix, + APIError, ConnectionId, EndpointType, LemmyError, diff --git a/server/src/api/mod.rs b/server/src/api/mod.rs index 03a585f7f..a1b8c188d 100644 --- a/server/src/api/mod.rs +++ b/server/src/api/mod.rs @@ -1,6 +1,5 @@ use crate::{api::claims::Claims, blocking, DbPool, LemmyContext}; use actix_web::web::Data; -use lemmy_api_structs::APIError; use lemmy_db::{ community::Community, community_view::CommunityUserBanView, @@ -8,7 +7,7 @@ use lemmy_db::{ user::User_, Crud, }; -use lemmy_utils::{slur_check, slurs_vec_to_str, ConnectionId, LemmyError}; +use lemmy_utils::{slur_check, slurs_vec_to_str, APIError, ConnectionId, LemmyError}; pub mod claims; pub mod comment; diff --git a/server/src/api/post.rs b/server/src/api/post.rs index 0eeaae43e..9e1e97d51 100644 --- a/server/src/api/post.rs +++ b/server/src/api/post.rs @@ -18,7 +18,7 @@ use crate::{ LemmyContext, }; use actix_web::web::Data; -use lemmy_api_structs::{post::*, APIError}; +use lemmy_api_structs::post::*; use lemmy_db::{ comment_view::*, community_view::*, @@ -36,6 +36,7 @@ use lemmy_db::{ use lemmy_utils::{ is_valid_post_title, make_apub_endpoint, + APIError, ConnectionId, EndpointType, LemmyError, diff --git a/server/src/api/site.rs b/server/src/api/site.rs index abc4161e7..8bcc4b77a 100644 --- a/server/src/api/site.rs +++ b/server/src/api/site.rs @@ -18,7 +18,7 @@ use crate::{ }; use actix_web::web::Data; use anyhow::Context; -use lemmy_api_structs::{site::*, user::Register, APIError}; +use lemmy_api_structs::{site::*, user::Register}; use lemmy_db::{ category::*, comment_view::*, @@ -35,7 +35,7 @@ use lemmy_db::{ SearchType, SortType, }; -use lemmy_utils::{location_info, settings::Settings, ConnectionId, LemmyError}; +use lemmy_utils::{location_info, settings::Settings, APIError, ConnectionId, LemmyError}; use log::{debug, info}; use std::str::FromStr; diff --git a/server/src/api/user.rs b/server/src/api/user.rs index a40f296e8..1a71b3aa0 100644 --- a/server/src/api/user.rs +++ b/server/src/api/user.rs @@ -14,7 +14,7 @@ use anyhow::Context; use bcrypt::verify; use captcha::{gen, Difficulty}; use chrono::Duration; -use lemmy_api_structs::{user::*, APIError}; +use lemmy_api_structs::user::*; use lemmy_db::{ comment::*, comment_view::*, @@ -51,6 +51,7 @@ use lemmy_utils::{ remove_slurs, send_email, settings::Settings, + APIError, ConnectionId, EndpointType, LemmyError, diff --git a/server/src/websocket/chat_server.rs b/server/src/websocket/chat_server.rs index cb73b4644..b8066eece 100644 --- a/server/src/websocket/chat_server.rs +++ b/server/src/websocket/chat_server.rs @@ -13,9 +13,18 @@ use diesel::{ r2d2::{ConnectionManager, Pool}, PgConnection, }; -use lemmy_api_structs::{comment::*, community::*, post::*, site::*, user::*, APIError}; +use lemmy_api_structs::{comment::*, community::*, post::*, site::*, user::*}; use lemmy_rate_limit::RateLimit; -use lemmy_utils::{location_info, CommunityId, ConnectionId, IPAddr, LemmyError, PostId, UserId}; +use lemmy_utils::{ + location_info, + APIError, + CommunityId, + ConnectionId, + IPAddr, + LemmyError, + PostId, + UserId, +}; use rand::rngs::ThreadRng; use reqwest::Client; use serde::Serialize;