mirror of
https://github.com/magefree/mage.git
synced 2025-12-21 11:02:00 -08:00
another improvement to cannot connect message
This commit is contained in:
parent
0b19f91ffd
commit
550ad2bc69
1 changed files with 24 additions and 14 deletions
|
|
@ -33,6 +33,7 @@ import java.net.ConnectException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.PasswordAuthentication;
|
import java.net.PasswordAuthentication;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
|
import java.net.SocketTimeoutException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -187,20 +188,7 @@ public class Session {
|
||||||
// TODO: download client that matches server version
|
// TODO: download client that matches server version
|
||||||
} catch (CannotConnectException ex) {
|
} catch (CannotConnectException ex) {
|
||||||
if (!canceled) {
|
if (!canceled) {
|
||||||
Throwable t = ex.getCause();
|
handleCannotConnectException(ex);
|
||||||
String message = "";
|
|
||||||
while (t != null) {
|
|
||||||
if (t instanceof ConnectException) {
|
|
||||||
message = "Server is likely offline.";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (t instanceof SocketException) {
|
|
||||||
message = "Check your internet connection.";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
t = t.getCause();
|
|
||||||
}
|
|
||||||
client.showMessage("Unable to connect to server. " + message);
|
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
logger.fatal("Unable to connect to server - ", t);
|
logger.fatal("Unable to connect to server - ", t);
|
||||||
|
|
@ -212,6 +200,28 @@ public class Session {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleCannotConnectException(CannotConnectException ex) {
|
||||||
|
logger.warn("Cannot connect", ex);
|
||||||
|
Throwable t = ex.getCause();
|
||||||
|
String message = "";
|
||||||
|
while (t != null) {
|
||||||
|
if (t instanceof ConnectException) {
|
||||||
|
message = "Server is likely offline.";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (t instanceof SocketException) {
|
||||||
|
message = "Check your internet connection.";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (t instanceof SocketTimeoutException) {
|
||||||
|
message = "Server is not responding.";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
t = t.getCause();
|
||||||
|
}
|
||||||
|
client.showMessage("Unable to connect to server. " + message);
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void disconnect(boolean showMessage) {
|
public synchronized void disconnect(boolean showMessage) {
|
||||||
if (isConnected())
|
if (isConnected())
|
||||||
sessionState = SessionState.DISCONNECTING;
|
sessionState = SessionState.DISCONNECTING;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue