llldap/src/db/error.rs

46 lines
1.3 KiB
Rust

use std::fmt;
use crate::db::UserRef;
pub type BoxedError = Box<dyn std::error::Error + Send + Sync + 'static>;
#[derive(Debug)]
pub enum UserCreationError {
DomainNotFound(String),
UserAlreadyExists(UserRef),
Permissions,
}
impl fmt::Display for UserCreationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::DomainNotFound(domain) => write!(f, "No domain {domain} to create user in"),
Self::UserAlreadyExists(user) => write!(f, "User already exists: {user}"),
Self::Permissions => write!(f, "You do not have permissions to create this user"),
}
}
}
impl std::error::Error for UserCreationError {}
#[derive(Debug)]
pub enum DomainCreationError {
DomainAlreadyExists(String),
InvalidDomain(String),
}
impl fmt::Display for DomainCreationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::DomainAlreadyExists(domain) => {
write!(f, "Cannot create domain {domain} because it already exists")
}
Self::InvalidDomain(domain) => write!(
f,
"Cannot create domain `{domain}` because it's not considered a valid domain"
),
}
}
}
impl std::error::Error for DomainCreationError {}