2 extern crate lazy_static;
4 extern crate strum_macros;
17 use crate::settings::Settings;
22 pub type ConnectionId = usize;
23 pub type PostId = i32;
24 pub type CommunityId = i32;
25 pub type UserId = i32;
26 pub type IpAddr = String;
29 macro_rules! location_info {
32 "None value at {}:{}, column {}",
40 #[derive(Debug, Error)]
41 #[error("{{\"error\":\"{message}\"}}")]
47 pub fn err(msg: &str) -> Self {
49 message: msg.to_string(),
55 pub struct LemmyError {
56 pub inner: anyhow::Error,
59 impl<T> From<T> for LemmyError
61 T: Into<anyhow::Error>,
63 fn from(t: T) -> Self {
64 LemmyError { inner: t.into() }
68 impl std::fmt::Display for LemmyError {
69 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
74 impl actix_web::error::ResponseError for LemmyError {
75 fn status_code(&self) -> StatusCode {
76 match self.inner.downcast_ref::<diesel::result::Error>() {
77 Some(diesel::result::Error::NotFound) => StatusCode::NOT_FOUND,
78 _ => StatusCode::INTERNAL_SERVER_ERROR,
84 pub static ref WEBFINGER_COMMUNITY_REGEX: Regex = Regex::new(&format!(
85 "^group:([a-z0-9_]{{3, 20}})@{}$",
86 Settings::get().hostname
89 pub static ref WEBFINGER_USER_REGEX: Regex = Regex::new(&format!(
90 "^acct:([a-z0-9_]{{3, 20}})@{}$",
91 Settings::get().hostname