use serde::Serialize; use thiserror::Error; #[derive(Error, Debug)] pub enum AppError { #[error("IO error: {0}")] Io(#[from] std::io::Error), #[error("Network error: {0}")] Reqwest(#[from] reqwest::Error), #[error("Internal error: {0}")] Internal(String), } impl Serialize for AppError { fn serialize(&self, serializer: S) -> Result where S: serde::Serializer, { serializer.serialize_str(&self.to_string()) } } impl From for AppError { fn from(s: String) -> Self { AppError::Internal(s) } } impl From<&str> for AppError { fn from(s: &str) -> Self { AppError::Internal(s.to_string()) } }