2 extern crate lazy_static;
4 extern crate strum_macros;
15 use crate::settings::Settings;
20 pub type ConnectionId = usize;
21 pub type PostId = i32;
22 pub type CommunityId = i32;
23 pub type UserId = i32;
24 pub type IPAddr = String;
27 macro_rules! location_info {
30 "None value at {}:{}, column {}",
38 #[derive(Debug, Error)]
39 #[error("{{\"error\":\"{message}\"}}")]
45 pub fn err(msg: &str) -> Self {
47 message: msg.to_string(),
53 pub struct LemmyError {
54 pub inner: anyhow::Error,
57 impl<T> From<T> for LemmyError
59 T: Into<anyhow::Error>,
61 fn from(t: T) -> Self {
62 LemmyError { inner: t.into() }
66 impl std::fmt::Display for LemmyError {
67 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
72 impl actix_web::error::ResponseError for LemmyError {
73 fn status_code(&self) -> StatusCode {
74 match self.inner.downcast_ref::<diesel::result::Error>() {
75 Some(diesel::result::Error::NotFound) => StatusCode::NOT_FOUND,
76 _ => StatusCode::INTERNAL_SERVER_ERROR,
82 pub static ref WEBFINGER_COMMUNITY_REGEX: Regex = Regex::new(&format!(
83 "^group:([a-z0-9_]{{3, 20}})@{}$",
84 Settings::get().hostname
87 pub static ref WEBFINGER_USER_REGEX: Regex = Regex::new(&format!(
88 "^acct:([a-z0-9_]{{3, 20}})@{}$",
89 Settings::get().hostname