From 448208337c3a404403e6b312dbe38555a2bf8ad5 Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Tue, 1 Apr 2025 21:13:25 +0100 Subject: fix(stanza): stanza errors pubsub error variant --- stanza/src/client/error.rs | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'stanza/src/client') 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, r#type: ErrorType, - // children (sequence) - error: StanzaError, + // TODO: children (sequence) + errors: Vec, text: Option, } 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 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 for Vec { + fn from(value: StanzaError) -> Self { + match value { + #[cfg(feature = "xep_0060")] + StanzaError::PubSub(error) => error.stanza_errors(), + _ => vec![value], + } + } +} -- cgit