diff --git a/packages/moxxmpp/lib/src/events.dart b/packages/moxxmpp/lib/src/events.dart
index 1e49c55..8b13013 100644
--- a/packages/moxxmpp/lib/src/events.dart
+++ b/packages/moxxmpp/lib/src/events.dart
@@ -63,6 +63,7 @@ class MessageEvent extends XmppEvent {
required this.isMarkable,
required this.encrypted,
required this.other,
+ this.error,
this.type,
this.oob,
this.sfs,
@@ -74,6 +75,7 @@ class MessageEvent extends XmppEvent {
this.funCancellation,
this.messageRetraction,
});
+ final StanzaError? error;
final String body;
final JID fromJid;
final JID toJid;
diff --git a/packages/moxxmpp/lib/src/message.dart b/packages/moxxmpp/lib/src/message.dart
index b029a11..204a219 100644
--- a/packages/moxxmpp/lib/src/message.dart
+++ b/packages/moxxmpp/lib/src/message.dart
@@ -99,6 +99,7 @@ class MessageManager extends XmppManagerBase {
encrypted: state.encrypted,
messageRetraction: state.messageRetraction,
other: state.other,
+ error: StanzaError.fromStanza(message),
),);
return state.copyWith(done: true);
diff --git a/packages/moxxmpp/lib/src/stanza.dart b/packages/moxxmpp/lib/src/stanza.dart
index 9c8df98..f6993c1 100644
--- a/packages/moxxmpp/lib/src/stanza.dart
+++ b/packages/moxxmpp/lib/src/stanza.dart
@@ -1,6 +1,28 @@
import 'package:moxxmpp/src/namespaces.dart';
import 'package:moxxmpp/src/stringxml.dart';
+/// A simple description of the element that may be inside a stanza
+class StanzaError {
+ StanzaError(this.type, this.error);
+ String type;
+ String error;
+
+ /// Returns a StanzaError if [stanza] contains a element. If not, returns
+ /// null.
+ static StanzaError? fromStanza(Stanza stanza) {
+ final error = stanza.firstTag('error');
+ if (error == null) return null;
+
+ final stanzaError = error.firstTagByXmlns(fullStanzaXmlns);
+ if (stanzaError == null) return null;
+
+ return StanzaError(
+ error.attributes['type']! as String,
+ stanzaError.tag,
+ );
+ }
+}
+
class Stanza extends XMLNode {
// ignore: use_super_parameters
Stanza({ this.to, this.from, this.type, this.id, List children = const [], required String tag, Map attributes = const {} }) : super(