mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-26 14:02:06 +01:00
Provide a hint in NotConnectedException
that connect() needs to be called prior login(). SMACK-686
This commit is contained in:
parent
38b8016ab7
commit
9884eee85d
2 changed files with 13 additions and 4 deletions
|
@ -403,7 +403,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
*/
|
*/
|
||||||
public synchronized void login() throws XMPPException, SmackException, IOException {
|
public synchronized void login() throws XMPPException, SmackException, IOException {
|
||||||
if (isAnonymous()) {
|
if (isAnonymous()) {
|
||||||
throwNotConnectedExceptionIfAppropriate();
|
throwNotConnectedExceptionIfAppropriate("Did you call connect() before login()?");
|
||||||
throwAlreadyLoggedInExceptionIfAppropriate();
|
throwAlreadyLoggedInExceptionIfAppropriate();
|
||||||
loginAnonymously();
|
loginAnonymously();
|
||||||
} else {
|
} else {
|
||||||
|
@ -584,8 +584,12 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void throwNotConnectedExceptionIfAppropriate() throws NotConnectedException {
|
protected void throwNotConnectedExceptionIfAppropriate() throws NotConnectedException {
|
||||||
|
throwNotConnectedExceptionIfAppropriate(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void throwNotConnectedExceptionIfAppropriate(String optionalHint) throws NotConnectedException {
|
||||||
if (!isConnected()) {
|
if (!isConnected()) {
|
||||||
throw new NotConnectedException();
|
throw new NotConnectedException(optionalHint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright 2014 Florian Schmaus
|
* Copyright 2014-2015 Florian Schmaus
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -152,7 +152,12 @@ public class SmackException extends Exception {
|
||||||
private static final long serialVersionUID = 9197980400776001173L;
|
private static final long serialVersionUID = 9197980400776001173L;
|
||||||
|
|
||||||
public NotConnectedException() {
|
public NotConnectedException() {
|
||||||
super("Client is not, or no longer, connected");
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotConnectedException(String optionalHint) {
|
||||||
|
super("Client is not, or no longer, connected."
|
||||||
|
+ (optionalHint != null ? ' ' + optionalHint : ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue