use std::fmt;
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum AccessError {
EmptyRequest,
UnknownResource { resource: String },
UnknownAction { resource: String, action: String },
ResourceDenied { resource: String },
UnauthorizedResource { resource: String },
NotAuthorized,
}
impl fmt::Display for AccessError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::EmptyRequest => f.write_str("access request must include at least one resource"),
Self::UnknownResource { resource } => {
write!(f, "unknown access resource `{resource}`")
}
Self::UnknownAction { resource, action } => {
write!(
f,
"unknown action `{action}` for access resource `{resource}`"
)
}
Self::ResourceDenied { resource } => {
write!(f, "not allowed to access resource `{resource}`")
}
Self::UnauthorizedResource { resource } => {
write!(f, "unauthorized to access resource `{resource}`")
}
Self::NotAuthorized => f.write_str("not authorized"),
}
}
}
impl std::error::Error for AccessError {}