diff options
Diffstat (limited to 'stanza/src/stream.rs')
-rw-r--r-- | stanza/src/stream.rs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/stanza/src/stream.rs b/stanza/src/stream.rs index 069dcd1..60b13bc 100644 --- a/stanza/src/stream.rs +++ b/stanza/src/stream.rs @@ -1,6 +1,9 @@ +use std::fmt::Display; + use jid::JID; use peanuts::element::{ElementBuilder, FromElement, IntoElement}; use peanuts::Element; +use thiserror::Error; use crate::bind; @@ -176,12 +179,24 @@ impl FromElement for Feature { } } -#[derive(Debug)] +#[derive(Error, Debug)] pub struct Error { error: StreamError, text: Option<Text>, } +impl Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.error)?; + if let Some(text) = &self.text { + if let Some(text) = &text.text { + write!(f, ": {}", text)?; + } + } + Ok(()) + } +} + impl FromElement for Error { fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> { element.check_name("error")?; |