diff options
| author | 2025-02-25 19:11:25 +0000 | |
|---|---|---|
| committer | 2025-02-25 19:11:25 +0000 | |
| commit | 4fe4ab9d838ff967395ebaf79145163d28e7db74 (patch) | |
| tree | 79f454f9e64c52a05d3173598f5e549e42c589f9 /stanza/src | |
| parent | 3c412ea6b05fbc0c399cf95e1658bfd50492e722 (diff) | |
| download | luz-4fe4ab9d838ff967395ebaf79145163d28e7db74.tar.gz luz-4fe4ab9d838ff967395ebaf79145163d28e7db74.tar.bz2 luz-4fe4ab9d838ff967395ebaf79145163d28e7db74.zip | |
implement Error for stanza crate error types
Diffstat (limited to '')
| -rw-r--r-- | stanza/src/stanza_error.rs | 31 | ||||
| -rw-r--r-- | stanza/src/stream_error.rs | 28 | 
2 files changed, 54 insertions, 5 deletions
| diff --git a/stanza/src/stanza_error.rs b/stanza/src/stanza_error.rs index 99c1f15..6aec98c 100644 --- a/stanza/src/stanza_error.rs +++ b/stanza/src/stanza_error.rs @@ -4,32 +4,55 @@ use peanuts::{      element::{FromElement, IntoElement},      Element, XML_NS,  }; +use thiserror::Error;  pub const XMLNS: &str = "urn:ietf:params:xml:ns:xmpp-stanzas"; -#[derive(Clone, Debug)] +#[derive(Error, Clone, Debug)]  pub enum Error { +    #[error("bad request")]      BadRequest, +    #[error("conflict")]      Conflict, +    #[error("feature not implemented")]      FeatureNotImplemented, +    #[error("forbidden")]      Forbidden, +    #[error("gone: {0:?}")]      Gone(Option<String>), +    #[error("internal server error")]      InternalServerError, +    #[error("item not found")]      ItemNotFound, -    JidMalformed, +    #[error("JID malformed")] +    JIDMalformed, +    #[error("not acceptable")]      NotAcceptable, +    #[error("not allowed")]      NotAllowed, +    #[error("not authorized")]      NotAuthorized, +    #[error("policy violation")]      PolicyViolation, +    #[error("recipient unavailable")]      RecipientUnavailable, +    #[error("redirect: {0:?}")]      Redirect(Option<String>), +    #[error("registration required")]      RegistrationRequired, +    #[error("remote server not found")]      RemoteServerNotFound, +    #[error("remote server timeout")]      RemoteServerTimeout, +    #[error("resource constraint")]      ResourceConstraint, +    #[error("service unavailable")]      ServiceUnavailable, +    #[error("subscription required")]      SubscriptionRequired, +    #[error("undefined condition")]      UndefinedCondition, +    #[error("unexpected request")]      UnexpectedRequest,  } @@ -44,7 +67,7 @@ impl FromElement for Error {              (Some(XMLNS), "gone") => return Ok(Error::Gone(element.pop_value_opt()?)),              (Some(XMLNS), "internal-server-error") => error = Error::InternalServerError,              (Some(XMLNS), "item-not-found") => error = Error::ItemNotFound, -            (Some(XMLNS), "jid-malformed") => error = Error::JidMalformed, +            (Some(XMLNS), "jid-malformed") => error = Error::JIDMalformed,              (Some(XMLNS), "not-acceptable") => error = Error::NotAcceptable,              (Some(XMLNS), "not-allowed") => error = Error::NotAllowed,              (Some(XMLNS), "not-authorized") => error = Error::NotAuthorized, @@ -78,7 +101,7 @@ impl IntoElement for Error {              Error::Gone(r) => Element::builder("gone", Some(XMLNS)).push_text_opt(r.clone()),              Error::InternalServerError => Element::builder("internal-server-error", Some(XMLNS)),              Error::ItemNotFound => Element::builder("item-not-found", Some(XMLNS)), -            Error::JidMalformed => Element::builder("jid-malformed", Some(XMLNS)), +            Error::JIDMalformed => Element::builder("jid-malformed", Some(XMLNS)),              Error::NotAcceptable => Element::builder("not-acceptable", Some(XMLNS)),              Error::NotAllowed => Element::builder("not-allowed", Some(XMLNS)),              Error::NotAuthorized => Element::builder("not-authorized", Some(XMLNS)), diff --git a/stanza/src/stream_error.rs b/stanza/src/stream_error.rs index 5ae04a6..c1537ff 100644 --- a/stanza/src/stream_error.rs +++ b/stanza/src/stream_error.rs @@ -2,35 +2,61 @@ use peanuts::{      element::{FromElement, IntoElement},      DeserializeError, Element, XML_NS,  }; +use thiserror::Error;  pub const XMLNS: &str = "urn:ietf:params:xml:ns:xmpp-streams"; -#[derive(Clone, Debug)] +#[derive(Error, Clone, Debug)]  pub enum Error { +    #[error("bad format")]      BadFormat, +    #[error("bad namespace prefix")]      BadNamespacePrefix, +    #[error("conflict")]      Conflict, +    #[error("connection timeout")]      ConnectionTimeout, +    #[error("host gone")]      HostGone, +    #[error("host unknown")]      HostUnknown, +    #[error("improper addressing")]      ImproperAddressing, +    #[error("internal server error")]      InternalServerError, +    #[error("invalid from")]      InvalidFrom, +    #[error("invalid id")]      InvalidId, +    #[error("invalid namespace")]      InvalidNamespace, +    #[error("invalid xml")]      InvalidXml, +    #[error("not authorized")]      NotAuthorized, +    #[error("not well formed")]      NotWellFormed, +    #[error("policy violation")]      PolicyViolation, +    #[error("remote connection failed")]      RemoteConnectionFailed, +    #[error("reset")]      Reset, +    #[error("resource constraint")]      ResourceConstraint, +    #[error("restricted xml")]      RestrictedXml, +    #[error("see other host: {0:?}")]      SeeOtherHost(Option<String>), +    #[error("system shutdown")]      SystemShutdown, +    #[error("undefined condition")]      UndefinedCondition, +    #[error("unsupported encoding")]      UnsupportedEncoding, +    #[error("unsupported stanza type")]      UnsupportedStanzaType, +    #[error("unsupported version")]      UnsupportedVersion,  } | 
