use std::fmt;
#[derive(Debug, Clone)]
pub enum AdminError {
UserNotFound(String),
OrganizationNotFound(String),
InviteNotFound(String),
NotAuthorized,
Storage(String),
InvalidParameter(String),
NotSupported(String),
InviteExpired,
InviteAlreadyUsed,
InviteAlreadyExists(String),
}
impl fmt::Display for AdminError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::UserNotFound(id) => write!(f, "user not found: {}", id),
Self::OrganizationNotFound(id) => write!(f, "organization not found: {}", id),
Self::InviteNotFound(id) => write!(f, "invitation not found: {}", id),
Self::NotAuthorized => write!(f, "not authorized: admin access required"),
Self::Storage(msg) => write!(f, "storage error: {}", msg),
Self::InvalidParameter(msg) => write!(f, "invalid parameter: {}", msg),
Self::NotSupported(msg) => write!(f, "not supported: {}", msg),
Self::InviteExpired => write!(f, "invitation has expired"),
Self::InviteAlreadyUsed => write!(f, "invitation has already been used"),
Self::InviteAlreadyExists(email) => {
write!(f, "pending invitation already exists for: {}", email)
}
}
}
}
impl std::error::Error for AdminError {}
impl From<crate::TidewayError> for AdminError {
fn from(err: crate::TidewayError) -> Self {
Self::Storage(err.to_string())
}
}