StanzaListener not working for type='error'

Not sure if there’s a thread about this already, but I’ve been looking for this and haven’t seen anything useful yet.

So currently I am using Smack to create a chat, and everything is working fine, I just have one issue for handling errors, when I send a message and there’s an error, I am not able to handle the error because I can’t catch the stanza in any listener, so this is what I have:

I send this message:

<message

** from=‘user.a@domine.com/resource’**

** to=‘user.b@domine.com/resource’**

** type=‘chat’**

** xml:lang=‘en’**

** id=‘message_id’>**

** message**

and I have a stanza acknowledged listener, to listen the server when it gets the message, so I can mark my message as sent

mConnection.addStanzaAcknowledgedListener(packet -> {

** // In here update my local database for the message that I sent**

});

so in this listener, I get the same message that I sent (the one above).

My problem comes here, I get an error from the server, and basically I get the same message, but the type for this is error, which is fin, I can just look at the message_id and update my database and say that the message wasn’t sent

<message

** from=‘user.a@domine.com/resource’**

** to=‘user.b@domine.com/resource’**

** type=‘error’**

** xml:lang=‘en’**

** id=‘message_id’>**

** message**

** error message**

My problem is that I cannot get this message in any listener, I get that from the logs in the console, but I am not able to get any packet listener using filters to catch this message that I am getting with the error.

finally the question:

Is there any way to catch this stanza message for the type=‘error’? which listener should I use?

Have you tried a StanzaListener with MessageTypeFilter.ERROR?

@Flow I’ve been trying this:

connection.addPacketListener(packet -> {

Timber.d(“message: %s”, packet.toXML());
}, MessageTypeFilter.ERROR);

connection.addSyncStanzaListener(packet -> {

Timber.d(“message: %s”, packet.toXML());
}, MessageTypeFilter.ERROR);

connection.addAsyncStanzaListener(packet -> {

Timber.d(“message: %s”, packet.toXML());
}, MessageTypeFilter.ERROR);

still not able to catch the error.