use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum StackureError {
Validation(String),
Auth(String),
Forbidden(String),
Timeout(String),
Network(String),
}
impl StackureError {
#[must_use]
pub fn code(&self) -> &'static str {
match self {
Self::Validation(_) => "validation",
Self::Auth(_) => "auth",
Self::Forbidden(_) => "forbidden",
Self::Timeout(_) => "timeout",
Self::Network(_) => "network",
}
}
#[must_use]
pub fn message(&self) -> &str {
match self {
Self::Validation(m)
| Self::Auth(m)
| Self::Forbidden(m)
| Self::Timeout(m)
| Self::Network(m) => m,
}
}
}
impl fmt::Display for StackureError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "stackure: {}: {}", self.code(), self.message())
}
}
impl std::error::Error for StackureError {}