use ex3_common_error_info::ErrorInfo;
use ex3_canister_error::prelude::Error;
use ex3_canister_error::{impl_error_info_conversion, ErrorCode, ErrorKind, OtherError};
#[derive(Error, Debug, PartialEq, Clone, Eq)]
pub enum SecretVaultFactoryError {
#[error("Secret vault canister creating in progress")]
SecretVaultCreatingInProgress,
#[error("No permission to capacity alert")]
NoPermissionToCapacityAlert,
#[error("Max capacity alert call times reached")]
MaxCapacityAlertCallTimesReached,
#[error("Other error: {err:?}")]
Other { err: ErrorInfo },
}
impl ErrorCode for SecretVaultFactoryError {
fn error_code(&self) -> u32 {
let root_code = ErrorKind::error_code(&ErrorKind::SecretVaultFactory);
match self {
Self::SecretVaultCreatingInProgress => root_code + 1,
Self::NoPermissionToCapacityAlert => root_code + 2,
Self::MaxCapacityAlertCallTimesReached => root_code + 3,
Self::Other { err } => err.code,
}
}
}
impl_error_info_conversion!(SecretVaultFactoryError);
impl From<OtherError> for SecretVaultFactoryError {
fn from(error: OtherError) -> Self {
Self::Other { err: error.into() }
}
}