use crate::domain::ProtocolVersion;
use crate::domain::feature::Feature;
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum GatedError {
#[error("{feature} was not negotiated (session is {negotiated})")]
FeatureUnavailable {
feature: Feature,
negotiated: ProtocolVersion,
},
#[error("this request has no progress token; the client did not open one")]
NoProgressToken,
#[error("this server has no request-state key to seal with")]
NoStateKey,
#[error("the exchange did not complete: {reason}")]
MalformedAnswer {
reason: String,
},
}
impl GatedError {
#[must_use]
pub const fn feature(&self) -> Option<Feature> {
match self {
Self::FeatureUnavailable { feature, .. } => Some(*feature),
Self::NoProgressToken | Self::NoStateKey | Self::MalformedAnswer { .. } => None,
}
}
#[must_use]
pub const fn wrote_nothing(&self) -> bool {
match self {
Self::FeatureUnavailable { .. } | Self::NoProgressToken | Self::NoStateKey => true,
Self::MalformedAnswer { .. } => false,
}
}
}