1package im.conversations.android.xmpp;
2
3import com.google.common.base.Strings;
4import im.conversations.android.xmpp.model.error.Condition;
5import im.conversations.android.xmpp.model.error.Error;
6import im.conversations.android.xmpp.model.stanza.Iq;
7
8public class IqErrorException extends Exception {
9
10 private final Iq response;
11
12 public IqErrorException(Iq response) {
13 super(getErrorText(response));
14 this.response = response;
15 }
16
17 public Error getError() {
18 return this.response.getError();
19 }
20
21 private static String getErrorText(final Iq response) {
22 final var error = response.getError();
23 final var text = error == null ? null : error.getText();
24 final var textContent = text == null ? null : text.getContent();
25 if (Strings.isNullOrEmpty(textContent)) {
26 final var condition = error == null ? null : error.getExtension(Condition.class);
27 return condition == null ? null : condition.getName();
28 }
29 return textContent;
30 }
31
32 public Iq getResponse() {
33 return this.response;
34 }
35}