use std::error::Error;
use std::fmt;
use crate::error::{ConstraintViolationError, InternalError, ResourceTemporarilyUnavailableError};
#[derive(Debug)]
pub enum AgentStoreError {
InternalError(InternalError),
ConstraintViolationError(ConstraintViolationError),
ResourceTemporarilyUnavailableError(ResourceTemporarilyUnavailableError),
NotFoundError(String),
}
impl Error for AgentStoreError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
AgentStoreError::InternalError(err) => Some(err),
AgentStoreError::ConstraintViolationError(err) => Some(err),
AgentStoreError::ResourceTemporarilyUnavailableError(err) => Some(err),
AgentStoreError::NotFoundError(_) => None,
}
}
}
impl fmt::Display for AgentStoreError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
AgentStoreError::InternalError(err) => err.fmt(f),
AgentStoreError::ConstraintViolationError(err) => err.fmt(f),
AgentStoreError::ResourceTemporarilyUnavailableError(err) => err.fmt(f),
AgentStoreError::NotFoundError(ref s) => write!(f, "Agent not found: {}", s),
}
}
}