use crate::kind::AppError;
#[must_use]
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
#[allow(clippy::struct_excessive_bools)]
pub struct ErrorClassification {
retryable: bool,
alertable: bool,
security_signal: bool,
user_fixable: bool,
}
impl ErrorClassification {
pub fn for_error(err: &AppError) -> Self {
match err {
AppError::Validation { .. } | AppError::NotFound | AppError::Conflict => Self {
retryable: false,
alertable: false,
security_signal: false,
user_fixable: true,
},
AppError::Forbidden { .. } | AppError::Crypto => Self {
retryable: false,
alertable: true,
security_signal: true,
user_fixable: false,
},
AppError::Dependency { .. } => Self {
retryable: true,
alertable: true,
security_signal: false,
user_fixable: false,
},
AppError::Internal => Self {
retryable: false,
alertable: true,
security_signal: false,
user_fixable: false,
},
AppError::RateLimit { .. } => Self {
retryable: true,
alertable: false,
security_signal: false,
user_fixable: true,
},
}
}
#[must_use]
pub const fn is_retryable(&self) -> bool {
self.retryable
}
#[must_use]
pub const fn is_alertable(&self) -> bool {
self.alertable
}
#[must_use]
pub const fn is_security_signal(&self) -> bool {
self.security_signal
}
#[must_use]
pub const fn is_user_fixable(&self) -> bool {
self.user_fixable
}
}