diff options
Diffstat (limited to 'stanza/src/stanza_error.rs')
-rw-r--r-- | stanza/src/stanza_error.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/stanza/src/stanza_error.rs b/stanza/src/stanza_error.rs index a4b58bc..664a168 100644 --- a/stanza/src/stanza_error.rs +++ b/stanza/src/stanza_error.rs @@ -6,6 +6,9 @@ use peanuts::{ }; use thiserror::Error; +#[cfg(feature = "xep_0060")] +use crate::xep_0060::{self, errors::Error as PubsubError}; + pub const XMLNS: &str = "urn:ietf:params:xml:ns:xmpp-stanzas"; #[derive(Error, Clone, Debug)] @@ -54,6 +57,10 @@ pub enum Error { UndefinedCondition, #[error("unexpected request")] UnexpectedRequest, + #[cfg(feature = "xep_0060")] + #[error("pubsub: {0}")] + PubSub(#[from] PubsubError), + // TODO: unrecognized error } impl FromElement for Error { @@ -82,9 +89,13 @@ impl FromElement for Error { (Some(XMLNS), "subscription-required") => error = Error::SubscriptionRequired, (Some(XMLNS), "undefined-condition") => error = Error::UndefinedCondition, (Some(XMLNS), "unexpected-request") => error = Error::UnexpectedRequest, + #[cfg(feature = "xep_0060")] + (Some(xep_0060::errors::XMLNS), _) => { + error = Error::PubSub(PubsubError::from_element(element)?) + } _ => return Err(peanuts::DeserializeError::UnexpectedElement(element)), } - element.no_more_content()?; + // element.no_more_content()?; return Ok(error); } } @@ -118,6 +129,8 @@ impl IntoElement for Error { Error::SubscriptionRequired => Element::builder("subscription-required", Some(XMLNS)), Error::UndefinedCondition => Element::builder("undefined-condition", Some(XMLNS)), Error::UnexpectedRequest => Element::builder("unexpected-request", Some(XMLNS)), + #[cfg(feature = "xep_0060")] + Error::PubSub(pubsub) => pubsub.builder(), } } } |