#[derive(Debug, Clone, thiserror::Error)]
pub enum SchemaRegistryError {
#[error("schema id {0} not found in registry")]
NotFound(u32),
#[error("schema subject `{got}` not accepted (expected one of {accepted:?})")]
Incompatible { got: String, accepted: Vec<String> },
#[error("registry transport error (retriable={retriable}): {message}")]
Transport { retriable: bool, message: String },
#[error("failed to decode registry response: {0}")]
Decode(String),
}
impl SchemaRegistryError {
pub fn is_retriable(&self) -> bool {
matches!(
self,
SchemaRegistryError::Transport {
retriable: true,
..
}
)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn transport_5xx_is_retriable() {
let e = SchemaRegistryError::Transport {
retriable: true,
message: "503".into(),
};
assert!(e.is_retriable());
}
#[test]
fn not_found_is_not_retriable() {
assert!(!SchemaRegistryError::NotFound(7).is_retriable());
}
#[test]
fn transport_non_retriable_is_not_retriable() {
let e = SchemaRegistryError::Transport {
retriable: false,
message: "400".into(),
};
assert!(!e.is_retriable());
}
}