#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum OpenStreamError {
#[error("Open stream aborted (token: {token}){}", .reason.as_deref().map(|r| format!(": {r}")).unwrap_or_default())]
Abort {
token: String,
reason: Option<String>,
},
#[error("Open stream policy violation: {0}")]
Policy(String),
#[error("Open stream sequence error: {0}")]
Sequence(String),
}
impl OpenStreamError {
pub fn abort(token: impl Into<String>, reason: Option<String>) -> Self {
Self::Abort {
token: token.into(),
reason,
}
}
pub fn is_abort(&self) -> bool {
matches!(self, Self::Abort { .. })
}
}