diff --git a/src/error.rs b/src/error.rs index 2af1b3a..fc0f83b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -17,7 +17,7 @@ use std::error::Error as StdError; use std::fmt; use tokio_xmpp::Error as TokioXMPPError; -use xmpp_parsers::{Error as ParserError, FullJid, Jid}; +use xmpp_parsers::{Error as ParserError, FullJid, Jid, JidParseError}; #[derive(Debug)] pub enum Error { @@ -31,6 +31,8 @@ pub enum Error { SessionAlreadyExists(FullJid), /// Raised when fetching an occupant with a nickname that isn't assigned in the room. ParticipantNotFound(String), + /// Jid Parse errors + Jid(Box), /// TokioXMPP errors Xmpp(Box), /// Parser errors @@ -47,12 +49,19 @@ impl fmt::Display for Error { Error::NonexistantSession(err) => write!(f, "Session doesn't exist: {}", err), Error::SessionAlreadyExists(err) => write!(f, "Session already exist: {}", err), Error::ParticipantNotFound(err) => write!(f, "Participant not found: {}", err), + Error::Jid(err) => write!(f, "Jid Parse error: {}", err), Error::Xmpp(err) => write!(f, "XMPP error: {}", err), Error::Parser(err) => write!(f, "Parser error: {}", err), } } } +impl From for Error { + fn from(err: JidParseError) -> Error { + Error::Jid(Box::new(err)) + } +} + impl From for Error { fn from(err: TokioXMPPError) -> Error { Error::Xmpp(Box::new(err))