2 extern crate lazy_static;
4 extern crate strum_macros;
6 extern crate smart_default;
25 pub type ConnectionId = usize;
27 #[derive(PartialEq, Eq, Hash, Debug, Clone)]
28 pub struct IpAddr(pub String);
30 impl fmt::Display for IpAddr {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 write!(f, "{}", self.0)
37 macro_rules! location_info {
40 "None value at {}:{}, column {}",
48 #[derive(Debug, Error)]
49 #[error("{{\"error\":\"{message}\"}}")]
55 pub fn err(msg: &str) -> Self {
57 message: msg.to_string(),
63 pub struct LemmyError {
64 pub inner: anyhow::Error,
67 impl<T> From<T> for LemmyError
69 T: Into<anyhow::Error>,
71 fn from(t: T) -> Self {
72 LemmyError { inner: t.into() }
76 impl std::fmt::Display for LemmyError {
77 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
82 impl actix_web::error::ResponseError for LemmyError {
83 fn status_code(&self) -> StatusCode {
84 match self.inner.downcast_ref::<diesel::result::Error>() {
85 Some(diesel::result::Error::NotFound) => StatusCode::NOT_FOUND,
86 _ => StatusCode::INTERNAL_SERVER_ERROR,