Skip to content

Commit

Permalink
refactor: Move JidError from RequestError into ParseError
Browse files Browse the repository at this point in the history
  • Loading branch information
nesium committed Sep 4, 2024
1 parent c543066 commit 0c1b149
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use minidom::{Element, IntoAttributeValue};
use xmpp_parsers::pubsub::PubSubPayload;

use crate::domain::rooms::models::RoomSidebarState;
use prose_xmpp::{ElementExt, ParseError, RequestError};
use prose_xmpp::{ElementExt, ParseError};

use crate::domain::shared::models::{MucId, RoomId};
use crate::domain::sidebar::models::{Bookmark, BookmarkType};
Expand All @@ -21,7 +21,7 @@ pub mod ns {
}

impl TryFrom<Element> for Bookmark {
type Error = RequestError;
type Error = ParseError;

fn try_from(value: Element) -> Result<Self, Self::Error> {
value.expect_is("bookmark", ns::PROSE_BOOKMARK)?;
Expand Down Expand Up @@ -94,7 +94,7 @@ impl IntoAttributeValue for BookmarkType {
}

impl FromStr for BookmarkType {
type Err = RequestError;
type Err = ParseError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
Expand All @@ -103,9 +103,9 @@ impl FromStr for BookmarkType {
"private-channel" => Ok(Self::PrivateChannel),
"public-channel" => Ok(Self::PublicChannel),
"generic" => Ok(Self::Generic),
_ => Err(RequestError::ParseError(ParseError::Generic {
_ => Err(ParseError::Generic {
msg: format!("Unknown RoomType {}", s),
})),
}),
}
}
}
4 changes: 2 additions & 2 deletions crates/prose-xmpp/src/stanza/muc/muc_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Copyright: 2023, Marc Bauer <mb@nesium.com>
// License: Mozilla Public License v2.0 (MPL v2.0)

use crate::{ns, ElementExt, RequestError};
use crate::{ns, ElementExt, ParseError, RequestError};
use jid::BareJid;
use minidom::Element;
use std::str::FromStr;
Expand Down Expand Up @@ -103,7 +103,7 @@ impl From<MucUser> for Element {
}

impl TryFrom<Element> for Destroy {
type Error = RequestError;
type Error = ParseError;

fn try_from(root: Element) -> Result<Self, Self::Error> {
root.expect_is("destroy", ns::MUC_USER)?;
Expand Down
8 changes: 4 additions & 4 deletions crates/prose-xmpp/src/stanza/muc/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// Copyright: 2023, Marc Bauer <mb@nesium.com>
// License: Mozilla Public License v2.0 (MPL v2.0)

use crate::ns;
use crate::util::{ElementExt, RequestError};
use crate::{ns, ParseError};
use jid::{BareJid, Jid};
use minidom::{Element, NSChoice};
use std::str::FromStr;
Expand Down Expand Up @@ -128,7 +128,7 @@ impl ToString for Role {
}

impl TryFrom<Element> for Destroy {
type Error = RequestError;
type Error = ParseError;

fn try_from(root: Element) -> Result<Self, Self::Error> {
root.expect_is("destroy", ns::MUC_OWNER)?;
Expand Down Expand Up @@ -156,15 +156,15 @@ impl From<Destroy> for Element {
}

impl TryFrom<Element> for User {
type Error = RequestError;
type Error = ParseError;

fn try_from(root: Element) -> Result<Self, Self::Error> {
root.expect_is("item", NSChoice::AnyOf(&[ns::MUC_OWNER, ns::MUC_ADMIN]))?;

Ok(User {
jid: Jid::from_str(root.attr_req("jid")?)?,
affiliation: muc::user::Affiliation::from_str(root.attr_req("affiliation")?).map_err(
|err| RequestError::Generic {
|err| ParseError::Generic {
msg: err.to_string(),
},
)?,
Expand Down
4 changes: 2 additions & 2 deletions crates/prose-xmpp/src/util/request_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ pub enum RequestError {
UnexpectedResponse,
#[error("XMPP Error: {err:?}")]
XMPP { err: StanzaError },
#[error(transparent)]
JidError(#[from] jid::Error),
#[error("Request error: {msg}")]
Generic { msg: String },
#[error(transparent)]
Expand All @@ -34,6 +32,8 @@ pub enum ParseError {
XMPPParseError(#[from] xmpp_parsers::Error),
#[error(transparent)]
ParseIntError(#[from] std::num::ParseIntError),
#[error(transparent)]
JidError(#[from] jid::Error),
}

impl From<xmpp_parsers::Error> for RequestError {
Expand Down

0 comments on commit 0c1b149

Please sign in to comment.