#[derive(Debug, thiserror::Error)]
pub enum SendError {
#[error("provider error: {0}")]
Provider(String),
#[error("authentication error: {0}")]
Authentication(String),
#[error("invalid address: {0}")]
InvalidAddress(String),
#[error("inactive recipient: {0}")]
InactiveRecipient(String),
#[error("spam complaint: {0}")]
SpamComplaint(String),
#[error("hard bounce: {0}")]
HardBounce(String),
#[error("rate limit exceeded: {0}")]
RateLimitExceeded(String),
#[error("service unavailable: {0}")]
ServiceUnavailable(String),
#[error("api error {status}: {message}")]
Api { status: u16, message: String },
#[error("serialization error: {0}")]
Serialization(String),
#[error("batch too large: {count} emails exceeds provider limit of {limit}")]
BatchTooLarge { count: usize, limit: usize },
#[error("batch is empty")]
BatchEmpty,
#[error("all providers failed: {0:?}")]
AllProvidersFailed(Vec<SendError>),
}
impl SendError {
pub fn is_retryable(&self) -> bool {
matches!(
self,
SendError::Provider(_)
| SendError::RateLimitExceeded(_)
| SendError::ServiceUnavailable(_)
| SendError::Authentication(_)
)
}
}