aboutsummaryrefslogtreecommitdiffstats
path: root/stanza/src/xep_0060/errors.rs
diff options
context:
space:
mode:
Diffstat (limited to 'stanza/src/xep_0060/errors.rs')
-rw-r--r--stanza/src/xep_0060/errors.rs62
1 files changed, 62 insertions, 0 deletions
diff --git a/stanza/src/xep_0060/errors.rs b/stanza/src/xep_0060/errors.rs
index 10d1483..e6817ac 100644
--- a/stanza/src/xep_0060/errors.rs
+++ b/stanza/src/xep_0060/errors.rs
@@ -6,6 +6,8 @@ use peanuts::{
};
use thiserror::Error;
+use crate::{client::error::ErrorType, stanza_error::Error as StanzaError};
+
pub const XMLNS: &str = "http://jabber.org/protocol/pubsub#errors";
#[derive(Error, Clone, Debug)]
@@ -58,6 +60,66 @@ pub enum Error {
UnsupportedAccessModel,
}
+impl Error {
+ pub fn r#type(&self) -> ErrorType {
+ match self {
+ Error::ClosedNode => ErrorType::Cancel,
+ Error::ConfigurationRequired => ErrorType::Modify,
+ Error::InvalidJID => ErrorType::Modify,
+ Error::InvalidOptions => ErrorType::Modify,
+ Error::InvalidPayload => ErrorType::Modify,
+ Error::InvalidSubID => ErrorType::Modify,
+ Error::ItemForbidden => ErrorType::Modify,
+ Error::ItemRequired => ErrorType::Modify,
+ Error::JIDRequired => ErrorType::Modify,
+ Error::MaxItemsExceeded => ErrorType::Cancel,
+ Error::MaxNodesExceeded => ErrorType::Cancel,
+ Error::NodeIDRequired => ErrorType::Modify,
+ Error::NotInRosterGroup => ErrorType::Auth,
+ Error::NotSubscribed => ErrorType::Cancel,
+ Error::PayloadTooBig => ErrorType::Modify,
+ Error::PayloadRequired => ErrorType::Modify,
+ Error::PendingSubscription => ErrorType::Auth,
+ Error::PreconditionNotMet => ErrorType::Cancel,
+ Error::PresenceSubscriptionRequired => ErrorType::Auth,
+ Error::SubIDRequired => ErrorType::Modify,
+ Error::TooManySubscriptions => ErrorType::Wait,
+ Error::Unsupported(_feature) => ErrorType::Cancel,
+ Error::UnsupportedAccessModel => ErrorType::Modify,
+ }
+ }
+
+ pub fn stanza_errors(self) -> Vec<StanzaError> {
+ match self {
+ Error::ClosedNode => vec![StanzaError::NotAllowed, self.into()],
+ Error::ConfigurationRequired => vec![StanzaError::NotAcceptable, self.into()],
+ Error::InvalidJID => vec![StanzaError::BadRequest, self.into()],
+ Error::InvalidOptions => vec![StanzaError::BadRequest, self.into()],
+ Error::InvalidPayload => vec![StanzaError::BadRequest, self.into()],
+ Error::InvalidSubID => vec![StanzaError::NotAcceptable, self.into()],
+ Error::ItemForbidden => vec![StanzaError::BadRequest, self.into()],
+ Error::ItemRequired => vec![StanzaError::BadRequest, self.into()],
+ Error::JIDRequired => vec![StanzaError::BadRequest, self.into()],
+ Error::MaxItemsExceeded => vec![StanzaError::NotAllowed, self.into()],
+ Error::MaxNodesExceeded => vec![StanzaError::NotAllowed, self.into()],
+ Error::NodeIDRequired => vec![StanzaError::BadRequest, self.into()],
+ Error::NotInRosterGroup => vec![StanzaError::NotAuthorized, self.into()],
+ Error::NotSubscribed => vec![StanzaError::UnexpectedRequest, self.into()],
+ Error::PayloadTooBig => vec![StanzaError::NotAcceptable, self.into()],
+ Error::PayloadRequired => vec![StanzaError::BadRequest, self.into()],
+ Error::PendingSubscription => vec![StanzaError::NotAuthorized, self.into()],
+ Error::PreconditionNotMet => vec![StanzaError::Conflict, self.into()],
+ Error::PresenceSubscriptionRequired => vec![StanzaError::NotAuthorized, self.into()],
+ Error::SubIDRequired => vec![StanzaError::BadRequest, self.into()],
+ Error::TooManySubscriptions => vec![StanzaError::PolicyViolation, self.into()],
+ Error::Unsupported(ref _feature) => {
+ vec![StanzaError::FeatureNotImplemented, self.into()]
+ }
+ Error::UnsupportedAccessModel => vec![StanzaError::NotAcceptable, self.into()],
+ }
+ }
+}
+
impl FromElement for Error {
fn from_element(mut element: Element) -> peanuts::element::DeserializeResult<Self> {
match element.identify() {