diff options
author | 2025-04-01 21:13:25 +0100 | |
---|---|---|
committer | 2025-04-01 21:13:25 +0100 | |
commit | 448208337c3a404403e6b312dbe38555a2bf8ad5 (patch) | |
tree | 8a9ec3bd1948848897a0740d20ddaf040f3b4f90 /stanza/src/client/error.rs | |
parent | f7b88569987026bcfec6132ca97b1d8122f44edd (diff) | |
download | luz-448208337c3a404403e6b312dbe38555a2bf8ad5.tar.gz luz-448208337c3a404403e6b312dbe38555a2bf8ad5.tar.bz2 luz-448208337c3a404403e6b312dbe38555a2bf8ad5.zip |
fix(stanza): stanza errors pubsub error variant
Diffstat (limited to 'stanza/src/client/error.rs')
-rw-r--r-- | stanza/src/client/error.rs | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/stanza/src/client/error.rs b/stanza/src/client/error.rs index 33bc85e..c4ab517 100644 --- a/stanza/src/client/error.rs +++ b/stanza/src/client/error.rs @@ -14,14 +14,18 @@ use super::XMLNS; pub struct Error { by: Option<String>, r#type: ErrorType, - // children (sequence) - error: StanzaError, + // TODO: children (sequence) + errors: Vec<StanzaError>, text: Option<Text>, } impl Display for Error { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}, {}", self.r#type, self.error)?; + write!(f, "{},", self.r#type)?; + + for error in &self.errors { + write!(f, "{}: ", error)?; + } if let Some(text) = &self.text { if let Some(text) = &text.text { @@ -42,13 +46,13 @@ impl FromElement for Error { let by = element.attribute_opt("by")?; let r#type = element.attribute("type")?; - let error = element.pop_child_one()?; - let text = element.pop_child_opt()?; + let errors = element.children()?; + let text = element.child_opt()?; Ok(Error { by, r#type, - error, + errors, text, }) } @@ -59,7 +63,7 @@ impl IntoElement for Error { Element::builder("error", Some(XMLNS)) .push_attribute_opt("by", self.by.clone()) .push_attribute("type", self.r#type) - .push_child(self.error.clone()) + .push_children(self.errors.clone()) .push_child_opt(self.text.clone()) } } @@ -128,12 +132,24 @@ impl From<StanzaError> for Error { StanzaError::UndefinedCondition => ErrorType::Cancel, // wait or modify StanzaError::UnexpectedRequest => ErrorType::Modify, + #[cfg(feature = "xep_0060")] + StanzaError::PubSub(ref error) => error.r#type(), }; Self { by: None, r#type: error_type, - error: value, + errors: value.into(), text: None, } } } + +impl From<StanzaError> for Vec<StanzaError> { + fn from(value: StanzaError) -> Self { + match value { + #[cfg(feature = "xep_0060")] + StanzaError::PubSub(error) => error.stanza_errors(), + _ => vec![value], + } + } +} |