use std::error::Error;
use std::fmt;
use crate::error::InvalidStateError;
use crate::registry::error::RegistryError;
#[derive(Debug)]
pub enum RegistryRestApiError {
InternalError(String),
InvalidStateError(InvalidStateError),
}
impl Error for RegistryRestApiError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
RegistryRestApiError::InternalError(_) => None,
RegistryRestApiError::InvalidStateError(err) => Some(err),
}
}
}
impl fmt::Display for RegistryRestApiError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
RegistryRestApiError::InternalError(msg) => write!(f, "{}", msg),
RegistryRestApiError::InvalidStateError(err) => write!(f, "{}", err),
}
}
}
impl From<RegistryError> for RegistryRestApiError {
fn from(err: RegistryError) -> Self {
match err {
RegistryError::InvalidStateError(err) => RegistryRestApiError::InvalidStateError(err),
_ => RegistryRestApiError::InternalError(err.to_string()),
}
}
}