2 extern crate lazy_static;
4 extern crate strum_macros;
18 use crate::settings::structs::Settings;
23 pub type ConnectionId = usize;
24 pub type PostId = i32;
25 pub type CommunityId = i32;
26 pub type UserId = i32;
27 pub type IpAddr = String;
30 macro_rules! location_info {
33 "None value at {}:{}, column {}",
41 #[derive(Debug, Error)]
42 #[error("{{\"error\":\"{message}\"}}")]
48 pub fn err(msg: &str) -> Self {
50 message: msg.to_string(),
56 pub struct LemmyError {
57 pub inner: anyhow::Error,
60 impl<T> From<T> for LemmyError
62 T: Into<anyhow::Error>,
64 fn from(t: T) -> Self {
65 LemmyError { inner: t.into() }
69 impl std::fmt::Display for LemmyError {
70 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
75 impl actix_web::error::ResponseError for LemmyError {
76 fn status_code(&self) -> StatusCode {
77 match self.inner.downcast_ref::<diesel::result::Error>() {
78 Some(diesel::result::Error::NotFound) => StatusCode::NOT_FOUND,
79 _ => StatusCode::INTERNAL_SERVER_ERROR,
85 pub static ref WEBFINGER_COMMUNITY_REGEX: Regex = Regex::new(&format!(
86 "^group:([a-z0-9_]{{3, 20}})@{}$",
87 Settings::get().hostname()
89 .expect("compile webfinger regex");
90 pub static ref WEBFINGER_USER_REGEX: Regex = Regex::new(&format!(
91 "^acct:([a-z0-9_]{{3, 20}})@{}$",
92 Settings::get().hostname()
94 .expect("compile webfinger regex");