implement Error for stanza crate error types
This commit is contained in:
		
							parent
							
								
									3c412ea6b0
								
							
						
					
					
						commit
						4fe4ab9d83
					
				| 
						 | 
					@ -6,3 +6,4 @@ edition = "2021"
 | 
				
			||||||
[dependencies]
 | 
					[dependencies]
 | 
				
			||||||
peanuts = { version = "0.1.0", path = "../../peanuts" }
 | 
					peanuts = { version = "0.1.0", path = "../../peanuts" }
 | 
				
			||||||
jid = { version = "0.1.0", path = "../jid" }
 | 
					jid = { version = "0.1.0", path = "../jid" }
 | 
				
			||||||
 | 
					thiserror = "2.0.11"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,32 +4,55 @@ use peanuts::{
 | 
				
			||||||
    element::{FromElement, IntoElement},
 | 
					    element::{FromElement, IntoElement},
 | 
				
			||||||
    Element, XML_NS,
 | 
					    Element, XML_NS,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					use thiserror::Error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub const XMLNS: &str = "urn:ietf:params:xml:ns:xmpp-stanzas";
 | 
					pub const XMLNS: &str = "urn:ietf:params:xml:ns:xmpp-stanzas";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Clone, Debug)]
 | 
					#[derive(Error, Clone, Debug)]
 | 
				
			||||||
pub enum Error {
 | 
					pub enum Error {
 | 
				
			||||||
 | 
					    #[error("bad request")]
 | 
				
			||||||
    BadRequest,
 | 
					    BadRequest,
 | 
				
			||||||
 | 
					    #[error("conflict")]
 | 
				
			||||||
    Conflict,
 | 
					    Conflict,
 | 
				
			||||||
 | 
					    #[error("feature not implemented")]
 | 
				
			||||||
    FeatureNotImplemented,
 | 
					    FeatureNotImplemented,
 | 
				
			||||||
 | 
					    #[error("forbidden")]
 | 
				
			||||||
    Forbidden,
 | 
					    Forbidden,
 | 
				
			||||||
 | 
					    #[error("gone: {0:?}")]
 | 
				
			||||||
    Gone(Option<String>),
 | 
					    Gone(Option<String>),
 | 
				
			||||||
 | 
					    #[error("internal server error")]
 | 
				
			||||||
    InternalServerError,
 | 
					    InternalServerError,
 | 
				
			||||||
 | 
					    #[error("item not found")]
 | 
				
			||||||
    ItemNotFound,
 | 
					    ItemNotFound,
 | 
				
			||||||
    JidMalformed,
 | 
					    #[error("JID malformed")]
 | 
				
			||||||
 | 
					    JIDMalformed,
 | 
				
			||||||
 | 
					    #[error("not acceptable")]
 | 
				
			||||||
    NotAcceptable,
 | 
					    NotAcceptable,
 | 
				
			||||||
 | 
					    #[error("not allowed")]
 | 
				
			||||||
    NotAllowed,
 | 
					    NotAllowed,
 | 
				
			||||||
 | 
					    #[error("not authorized")]
 | 
				
			||||||
    NotAuthorized,
 | 
					    NotAuthorized,
 | 
				
			||||||
 | 
					    #[error("policy violation")]
 | 
				
			||||||
    PolicyViolation,
 | 
					    PolicyViolation,
 | 
				
			||||||
 | 
					    #[error("recipient unavailable")]
 | 
				
			||||||
    RecipientUnavailable,
 | 
					    RecipientUnavailable,
 | 
				
			||||||
 | 
					    #[error("redirect: {0:?}")]
 | 
				
			||||||
    Redirect(Option<String>),
 | 
					    Redirect(Option<String>),
 | 
				
			||||||
 | 
					    #[error("registration required")]
 | 
				
			||||||
    RegistrationRequired,
 | 
					    RegistrationRequired,
 | 
				
			||||||
 | 
					    #[error("remote server not found")]
 | 
				
			||||||
    RemoteServerNotFound,
 | 
					    RemoteServerNotFound,
 | 
				
			||||||
 | 
					    #[error("remote server timeout")]
 | 
				
			||||||
    RemoteServerTimeout,
 | 
					    RemoteServerTimeout,
 | 
				
			||||||
 | 
					    #[error("resource constraint")]
 | 
				
			||||||
    ResourceConstraint,
 | 
					    ResourceConstraint,
 | 
				
			||||||
 | 
					    #[error("service unavailable")]
 | 
				
			||||||
    ServiceUnavailable,
 | 
					    ServiceUnavailable,
 | 
				
			||||||
 | 
					    #[error("subscription required")]
 | 
				
			||||||
    SubscriptionRequired,
 | 
					    SubscriptionRequired,
 | 
				
			||||||
 | 
					    #[error("undefined condition")]
 | 
				
			||||||
    UndefinedCondition,
 | 
					    UndefinedCondition,
 | 
				
			||||||
 | 
					    #[error("unexpected request")]
 | 
				
			||||||
    UnexpectedRequest,
 | 
					    UnexpectedRequest,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -44,7 +67,7 @@ impl FromElement for Error {
 | 
				
			||||||
            (Some(XMLNS), "gone") => return Ok(Error::Gone(element.pop_value_opt()?)),
 | 
					            (Some(XMLNS), "gone") => return Ok(Error::Gone(element.pop_value_opt()?)),
 | 
				
			||||||
            (Some(XMLNS), "internal-server-error") => error = Error::InternalServerError,
 | 
					            (Some(XMLNS), "internal-server-error") => error = Error::InternalServerError,
 | 
				
			||||||
            (Some(XMLNS), "item-not-found") => error = Error::ItemNotFound,
 | 
					            (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-acceptable") => error = Error::NotAcceptable,
 | 
				
			||||||
            (Some(XMLNS), "not-allowed") => error = Error::NotAllowed,
 | 
					            (Some(XMLNS), "not-allowed") => error = Error::NotAllowed,
 | 
				
			||||||
            (Some(XMLNS), "not-authorized") => error = Error::NotAuthorized,
 | 
					            (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::Gone(r) => Element::builder("gone", Some(XMLNS)).push_text_opt(r.clone()),
 | 
				
			||||||
            Error::InternalServerError => Element::builder("internal-server-error", Some(XMLNS)),
 | 
					            Error::InternalServerError => Element::builder("internal-server-error", Some(XMLNS)),
 | 
				
			||||||
            Error::ItemNotFound => Element::builder("item-not-found", 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::NotAcceptable => Element::builder("not-acceptable", Some(XMLNS)),
 | 
				
			||||||
            Error::NotAllowed => Element::builder("not-allowed", Some(XMLNS)),
 | 
					            Error::NotAllowed => Element::builder("not-allowed", Some(XMLNS)),
 | 
				
			||||||
            Error::NotAuthorized => Element::builder("not-authorized", Some(XMLNS)),
 | 
					            Error::NotAuthorized => Element::builder("not-authorized", Some(XMLNS)),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,35 +2,61 @@ use peanuts::{
 | 
				
			||||||
    element::{FromElement, IntoElement},
 | 
					    element::{FromElement, IntoElement},
 | 
				
			||||||
    DeserializeError, Element, XML_NS,
 | 
					    DeserializeError, Element, XML_NS,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					use thiserror::Error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub const XMLNS: &str = "urn:ietf:params:xml:ns:xmpp-streams";
 | 
					pub const XMLNS: &str = "urn:ietf:params:xml:ns:xmpp-streams";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Clone, Debug)]
 | 
					#[derive(Error, Clone, Debug)]
 | 
				
			||||||
pub enum Error {
 | 
					pub enum Error {
 | 
				
			||||||
 | 
					    #[error("bad format")]
 | 
				
			||||||
    BadFormat,
 | 
					    BadFormat,
 | 
				
			||||||
 | 
					    #[error("bad namespace prefix")]
 | 
				
			||||||
    BadNamespacePrefix,
 | 
					    BadNamespacePrefix,
 | 
				
			||||||
 | 
					    #[error("conflict")]
 | 
				
			||||||
    Conflict,
 | 
					    Conflict,
 | 
				
			||||||
 | 
					    #[error("connection timeout")]
 | 
				
			||||||
    ConnectionTimeout,
 | 
					    ConnectionTimeout,
 | 
				
			||||||
 | 
					    #[error("host gone")]
 | 
				
			||||||
    HostGone,
 | 
					    HostGone,
 | 
				
			||||||
 | 
					    #[error("host unknown")]
 | 
				
			||||||
    HostUnknown,
 | 
					    HostUnknown,
 | 
				
			||||||
 | 
					    #[error("improper addressing")]
 | 
				
			||||||
    ImproperAddressing,
 | 
					    ImproperAddressing,
 | 
				
			||||||
 | 
					    #[error("internal server error")]
 | 
				
			||||||
    InternalServerError,
 | 
					    InternalServerError,
 | 
				
			||||||
 | 
					    #[error("invalid from")]
 | 
				
			||||||
    InvalidFrom,
 | 
					    InvalidFrom,
 | 
				
			||||||
 | 
					    #[error("invalid id")]
 | 
				
			||||||
    InvalidId,
 | 
					    InvalidId,
 | 
				
			||||||
 | 
					    #[error("invalid namespace")]
 | 
				
			||||||
    InvalidNamespace,
 | 
					    InvalidNamespace,
 | 
				
			||||||
 | 
					    #[error("invalid xml")]
 | 
				
			||||||
    InvalidXml,
 | 
					    InvalidXml,
 | 
				
			||||||
 | 
					    #[error("not authorized")]
 | 
				
			||||||
    NotAuthorized,
 | 
					    NotAuthorized,
 | 
				
			||||||
 | 
					    #[error("not well formed")]
 | 
				
			||||||
    NotWellFormed,
 | 
					    NotWellFormed,
 | 
				
			||||||
 | 
					    #[error("policy violation")]
 | 
				
			||||||
    PolicyViolation,
 | 
					    PolicyViolation,
 | 
				
			||||||
 | 
					    #[error("remote connection failed")]
 | 
				
			||||||
    RemoteConnectionFailed,
 | 
					    RemoteConnectionFailed,
 | 
				
			||||||
 | 
					    #[error("reset")]
 | 
				
			||||||
    Reset,
 | 
					    Reset,
 | 
				
			||||||
 | 
					    #[error("resource constraint")]
 | 
				
			||||||
    ResourceConstraint,
 | 
					    ResourceConstraint,
 | 
				
			||||||
 | 
					    #[error("restricted xml")]
 | 
				
			||||||
    RestrictedXml,
 | 
					    RestrictedXml,
 | 
				
			||||||
 | 
					    #[error("see other host: {0:?}")]
 | 
				
			||||||
    SeeOtherHost(Option<String>),
 | 
					    SeeOtherHost(Option<String>),
 | 
				
			||||||
 | 
					    #[error("system shutdown")]
 | 
				
			||||||
    SystemShutdown,
 | 
					    SystemShutdown,
 | 
				
			||||||
 | 
					    #[error("undefined condition")]
 | 
				
			||||||
    UndefinedCondition,
 | 
					    UndefinedCondition,
 | 
				
			||||||
 | 
					    #[error("unsupported encoding")]
 | 
				
			||||||
    UnsupportedEncoding,
 | 
					    UnsupportedEncoding,
 | 
				
			||||||
 | 
					    #[error("unsupported stanza type")]
 | 
				
			||||||
    UnsupportedStanzaType,
 | 
					    UnsupportedStanzaType,
 | 
				
			||||||
 | 
					    #[error("unsupported version")]
 | 
				
			||||||
    UnsupportedVersion,
 | 
					    UnsupportedVersion,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue