#[derive(Debug)]
pub enum ViewError {
Serialization(String),
Permission(String),
NotFound(String),
BadRequest(String),
Internal(String),
DatabaseError(String),
}
impl std::fmt::Display for ViewError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ViewError::Serialization(msg) => write!(f, "Serialization error: {}", msg),
ViewError::Permission(msg) => write!(f, "Permission denied: {}", msg),
ViewError::NotFound(msg) => write!(f, "Not found: {}", msg),
ViewError::BadRequest(msg) => write!(f, "Bad request: {}", msg),
ViewError::Internal(msg) => write!(f, "Internal error: {}", msg),
ViewError::DatabaseError(msg) => write!(f, "Database error: {}", msg),
}
}
}
impl std::error::Error for ViewError {}
impl From<ViewError> for reinhardt_core::exception::Error {
fn from(value: ViewError) -> Self {
match value {
ViewError::Serialization(m) => Self::Serialization(m),
ViewError::Permission(m) => Self::Authorization(m),
ViewError::NotFound(m) => Self::NotFound(m),
ViewError::BadRequest(m) => Self::Http(m),
ViewError::Internal(m) => Self::Internal(m),
ViewError::DatabaseError(m) => Self::Database(m),
}
}
}