diff --git a/parsers/src/stanza_error.rs b/parsers/src/stanza_error.rs index ec7ee764..2b53cd5e 100644 --- a/parsers/src/stanza_error.rs +++ b/parsers/src/stanza_error.rs @@ -245,7 +245,9 @@ impl TryFrom for StanzaError { fn try_from(elem: Element) -> Result { check_self!(elem, "error", DEFAULT_NS); - check_no_unknown_attributes!(elem, "error", ["type", "by"]); + // The code attribute has been deprecated in [XEP-0086](https://xmpp.org/extensions/xep-0086.html) + // which was deprecated in 2007. We don't error when it's here, but don't include it in the final struct. + check_no_unknown_attributes!(elem, "error", ["type", "by", "code"]); let mut stanza_error = StanzaError { type_: get_attr!(elem, "type", Required), @@ -388,4 +390,16 @@ mod tests { }; assert_eq!(message, "Error must have a defined-condition."); } + + #[test] + fn test_error_code() { + let elem: Element = r#" + + The feature requested is not implemented by the recipient or server and therefore cannot be processed. +"# + .parse() + .unwrap(); + let stanza_error = StanzaError::try_from(elem).unwrap(); + assert_eq!(stanza_error.type_, ErrorType::Cancel); + } }