Stanza.getErrorCondation only ever needs the tag name

This commit is contained in:
Daniel Gultsch 2021-03-18 11:35:41 +01:00
parent 6f1b71970d
commit b09a1432a3
3 changed files with 35 additions and 42 deletions

View File

@ -1797,7 +1797,7 @@ public class XmppConnectionService extends Service {
IqPacket request = mIqGenerator.deleteItem(Namespace.BOOKMARKS2, bookmark.getJid().asBareJid().toEscapedString()); IqPacket request = mIqGenerator.deleteItem(Namespace.BOOKMARKS2, bookmark.getJid().asBareJid().toEscapedString());
sendIqPacket(account, request, (a, response) -> { sendIqPacket(account, request, (a, response) -> {
if (response.getType() == IqPacket.TYPE.ERROR) { if (response.getType() == IqPacket.TYPE.ERROR) {
Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": unable to delete bookmark " + response.getError()); Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": unable to delete bookmark " + response.getErrorCondition());
} }
}); });
} else if (connection.getFeatures().bookmarksConversion()) { } else if (connection.getFeatures().bookmarksConversion()) {
@ -2867,13 +2867,12 @@ public class XmppConnectionService extends Service {
} }
@Override @Override
public void onFetchFailed(final Conversation conversation, Element error) { public void onFetchFailed(final Conversation conversation, final String errorCondition) {
if (conversation.getStatus() == Conversation.STATUS_ARCHIVED) { if (conversation.getStatus() == Conversation.STATUS_ARCHIVED) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": conversation (" + conversation.getJid() + ") got archived before IQ result"); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": conversation (" + conversation.getJid() + ") got archived before IQ result");
return; return;
} }
if (error != null && "remote-server-not-found".equals(error.getName())) { if ("remote-server-not-found".equals(errorCondition)) {
synchronized (account.inProgressConferenceJoins) { synchronized (account.inProgressConferenceJoins) {
account.inProgressConferenceJoins.remove(conversation); account.inProgressConferenceJoins.remove(conversation);
} }
@ -3239,7 +3238,7 @@ public class XmppConnectionService extends Service {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": received timeout waiting for conference configuration fetch"); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": received timeout waiting for conference configuration fetch");
} else { } else {
if (callback != null) { if (callback != null) {
callback.onFetchFailed(conversation, packet.getError()); callback.onFetchFailed(conversation, packet.getErrorCondition());
} }
} }
} }
@ -3534,7 +3533,7 @@ public class XmppConnectionService extends Service {
if (publicationResponse.getType() == IqPacket.TYPE.RESULT) { if (publicationResponse.getType() == IqPacket.TYPE.RESULT) {
callback.onAvatarPublicationSucceeded(); callback.onAvatarPublicationSucceeded();
} else { } else {
Log.d(Config.LOGTAG, "failed to publish vcard " + publicationResponse.getError()); Log.d(Config.LOGTAG, "failed to publish vcard " + publicationResponse.getErrorCondition());
callback.onAvatarPublicationFailed(R.string.error_publish_avatar_server_reject); callback.onAvatarPublicationFailed(R.string.error_publish_avatar_server_reject);
} }
}); });
@ -4817,7 +4816,7 @@ public class XmppConnectionService extends Service {
public interface OnConferenceConfigurationFetched { public interface OnConferenceConfigurationFetched {
void onConferenceConfigurationFetched(Conversation conversation); void onConferenceConfigurationFetched(Conversation conversation);
void onFetchFailed(Conversation conversation, Element error); void onFetchFailed(Conversation conversation, String errorCondition);
} }
public interface OnConferenceJoined { public interface OnConferenceJoined {

View File

@ -930,7 +930,7 @@ public class XmppConnection implements Runnable {
if (response.getType() == IqPacket.TYPE.RESULT) { if (response.getType() == IqPacket.TYPE.RESULT) {
sendRegistryRequest(); sendRegistryRequest();
} else { } else {
final Element error = response.getError(); final String error = response.getErrorCondition();
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": failed to pre auth. " + error); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": failed to pre auth. " + error);
throw new StateChangingError(Account.State.REGISTRATION_INVALID_TOKEN); throw new StateChangingError(Account.State.REGISTRATION_INVALID_TOKEN);
} }

View File

@ -18,28 +18,22 @@ abstract public class AbstractAcknowledgeableStanza extends AbstractStanza {
setAttribute("id", id); setAttribute("id", id);
} }
public Element getError() { private Element getErrorConditionElement() {
Element error = findChild("error"); final Element error = findChild("error");
if (error != null) { if (error == null) {
for(Element element : error.getChildren()) { return null;
}
for (final Element element : error.getChildren()) {
if (!element.getName().equals("text")) { if (!element.getName().equals("text")) {
return element; return element;
} }
} }
}
return null; return null;
} }
public String getErrorCondition() { public String getErrorCondition() {
Element error = findChild("error"); final Element condition = getErrorConditionElement();
if (error != null) { return condition == null ? null : condition.getName();
for(Element element : error.getChildren()) {
if (!element.getName().equals("text")) {
return element.getName();
}
}
}
return null;
} }
public boolean valid() { public boolean valid() {