1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-09 09:09:38 +02:00

Improve message of XMPPErrorException

by including the XMPP entity which send the XMPP error reply to us.

Also cleanup the no longer used constructors.
This commit is contained in:
Florian Schmaus 2016-11-29 16:40:08 +01:00
parent 9165e818d9
commit d976434bb3
7 changed files with 65 additions and 57 deletions

View file

@ -17,9 +17,11 @@
package org.jivesoftware.smack;
import org.jivesoftware.smack.packet.Nonza;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.StreamError;
import org.jivesoftware.smack.packet.XMPPError;
import org.jxmpp.jid.Jid;
/**
* A generic exception that is thrown when an error occurs performing an
@ -72,48 +74,28 @@ public abstract class XMPPException extends Exception {
*/
private static final long serialVersionUID = 212790389529249604L;
private final XMPPError error;
private final Stanza stanza;
/**
* Creates a new XMPPErrorException with the given builder.
*
* @param xmppErrorBuilder
* @deprecated Use {@link #XMPPErrorException(Stanza, XMPPError)} instead.
*/
@Deprecated
public XMPPErrorException(XMPPError.Builder xmppErrorBuilder) {
this(xmppErrorBuilder.build());
this(null, xmppErrorBuilder.build());
}
/**
* Creates a new XMPPException with the XMPPError that was the root case of the exception.
* Creates a new XMPPErrorException with the XMPPError that was the root case of the exception.
*
* @param error the root cause of the exception.
*/
public XMPPErrorException(XMPPError error) {
public XMPPErrorException(Stanza stanza, XMPPError error) {
super();
this.error = error;
}
/**
* Creates a new XMPPException with a description of the exception, an XMPPError, and the
* Throwable that was the root cause of the exception.
*
* @param message a description of the exception.
* @param error the root cause of the exception.
* @param wrappedThrowable the root cause of the exception.
* @deprecated use {@link #XMPPException.XMPPErrorException(XMPPError)} instead.
*/
@Deprecated
public XMPPErrorException(String message, XMPPError error, Throwable wrappedThrowable) {
super(message, wrappedThrowable);
this.error = error;
}
/**
* Creates a new XMPPException with a description of the exception and the XMPPException
* that was the root cause of the exception.
*
* @param message a description of the exception.
* @param error the root cause of the exception.
* @deprecated use {@link #XMPPException.XMPPErrorException(XMPPError)} instead.
*/
@Deprecated
public XMPPErrorException(String message, XMPPError error) {
super(message);
this.error = error;
this.stanza = stanza;
}
/**
@ -128,23 +110,53 @@ public abstract class XMPPException extends Exception {
@Override
public String getMessage() {
String superMessage = super.getMessage();
if (superMessage != null) {
return superMessage;
}
else {
return error.toString();
StringBuilder sb = new StringBuilder();
if (stanza != null) {
Jid from = stanza.getFrom();
if (from != null) {
sb.append("XMPP error reply received from " + from + ": ");
}
}
sb.append(error);
return sb.toString();
}
public static void ifHasErrorThenThrow(Stanza packet) throws XMPPErrorException {
XMPPError xmppError = packet.getError();
if (xmppError != null) {
throw new XMPPErrorException(xmppError);
throw new XMPPErrorException(packet, xmppError);
}
}
}
public static class FailedNonzaException extends XMPPException {
/**
*
*/
private static final long serialVersionUID = 1L;
private final XMPPError.Condition condition;
private final Nonza nonza;
public FailedNonzaException(Nonza nonza, XMPPError.Condition condition) {
this.condition = condition;
this.nonza = nonza;
}
public XMPPError.Condition getCondition() {
return condition;
}
public Nonza getNonza() {
return nonza;
}
}
public static class StreamErrorException extends XMPPException {
/**
*