1package eu.siacs.conversations.xmpp;
2
3import im.conversations.android.xmpp.model.stanza.Iq;
4
5public class IqErrorResponseException extends Exception {
6
7 private final Iq response;
8
9 public IqErrorResponseException(final Iq response) {
10 super(message(response));
11 this.response = response;
12 }
13
14 public Iq getResponse() {
15 return this.response;
16 }
17
18 public static String message(final Iq iq) {
19 final var error = iq.getError();
20 if (error == null) {
21 return "missing error element in response";
22 }
23 final var text = error.getTextAsString();
24 if (text != null) {
25 return text;
26 }
27 final var condition = error.getCondition();
28 if (condition != null) {
29 return condition.getName();
30 }
31 return "no condition attached to error";
32 }
33}