diff options
Diffstat (limited to 'stanza/src/client/error.rs')
-rw-r--r-- | stanza/src/client/error.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/stanza/src/client/error.rs b/stanza/src/client/error.rs index aa142bf..33bc85e 100644 --- a/stanza/src/client/error.rs +++ b/stanza/src/client/error.rs @@ -99,3 +99,41 @@ impl FromStr for ErrorType { } } } + +impl From<StanzaError> for Error { + fn from(value: StanzaError) -> Self { + let error_type = match value { + StanzaError::BadRequest => ErrorType::Modify, + StanzaError::Conflict => ErrorType::Cancel, + // cancel or modify + StanzaError::FeatureNotImplemented => ErrorType::Cancel, + StanzaError::Forbidden => ErrorType::Auth, + StanzaError::Gone(_) => ErrorType::Cancel, + StanzaError::InternalServerError => ErrorType::Cancel, + StanzaError::ItemNotFound => ErrorType::Cancel, + StanzaError::JIDMalformed => ErrorType::Modify, + StanzaError::NotAcceptable => ErrorType::Modify, + StanzaError::NotAllowed => ErrorType::Cancel, + StanzaError::NotAuthorized => ErrorType::Auth, + // modify or wait + StanzaError::PolicyViolation => ErrorType::Modify, + StanzaError::RecipientUnavailable => ErrorType::Wait, + StanzaError::Redirect(_) => ErrorType::Modify, + StanzaError::RegistrationRequired => ErrorType::Auth, + StanzaError::RemoteServerNotFound => ErrorType::Cancel, + StanzaError::RemoteServerTimeout => ErrorType::Wait, + StanzaError::ResourceConstraint => ErrorType::Wait, + StanzaError::ServiceUnavailable => ErrorType::Cancel, + StanzaError::SubscriptionRequired => ErrorType::Auth, + StanzaError::UndefinedCondition => ErrorType::Cancel, + // wait or modify + StanzaError::UnexpectedRequest => ErrorType::Modify, + }; + Self { + by: None, + r#type: error_type, + error: value, + text: None, + } + } +} |