#[derive(Debug, thiserror::Error)]
pub enum CedarError {
#[error("Cedar policy parse error: {0}")]
PolicyParse(String),
#[error("Cedar schema parse error: {0}")]
SchemaParse(String),
#[error("Policy load error: {0}")]
PolicyLoad(String),
#[error("Policy validation error: {0}")]
Validation(String),
#[error("Entity build error: {0}")]
EntityBuildFailed(String),
#[error("Authorization evaluation error: {0}")]
Evaluation(String),
#[error("Cedar configuration error: {0}")]
Config(String),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("Policy set error: {0}")]
PolicySet(String),
}
impl CedarError {
pub fn status_code(&self) -> u16 {
match self {
CedarError::Config(_) | CedarError::PolicyParse(_) | CedarError::SchemaParse(_) => 500,
CedarError::PolicyLoad(_) | CedarError::Validation(_) => 500,
CedarError::EntityBuildFailed(_) | CedarError::Evaluation(_) => 500,
CedarError::Io(_) | CedarError::PolicySet(_) => 500,
}
}
}
pub type CedarResult<T> = std::result::Result<T, CedarError>;