use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Debug, Serialize, Deserialize)] pub struct AppError { pub message: String, } impl fmt::Display for AppError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.message) } } impl std::error::Error for AppError {} impl AppError { pub fn new(message: impl Into) -> Self { Self { message: message.into(), } } } impl From for AppError { fn from(value: anyhow::Error) -> Self { Self::new(value.to_string()) } } impl From for AppError { fn from(value: std::io::Error) -> Self { Self::new(value.to_string()) } } impl From for AppError { fn from(value: serde_json::Error) -> Self { Self::new(value.to_string()) } } pub type AppResult = Result;