* Added some error handling for connect to server action.

This commit is contained in:
LevelX2 2015-02-07 18:15:11 +01:00
parent 974951e18d
commit ea8446d097
2 changed files with 32 additions and 3 deletions

View file

@ -328,7 +328,9 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
} }
public void setWindowTitle() { public void setWindowTitle() {
setTitle(TITLE_NAME + " Client: " + version.toString() + " Server: " + ((session != null && session.isConnected()) ? session.getVersionInfo():"<not connected>")); setTitle(TITLE_NAME + " Client: "
+ version == null ? "<not available>" : version.toString() + " Server: "
+ ((session != null && session.isConnected()) ? session.getVersionInfo():"<not connected>"));
} }
private void addTooltipContainer() { private void addTooltipContainer() {

View file

@ -28,6 +28,8 @@
package mage.remote; package mage.remote;
import java.io.IOException;
import java.lang.reflect.UndeclaredThrowableException;
import java.net.Authenticator; import java.net.Authenticator;
import java.net.ConnectException; import java.net.ConnectException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
@ -49,7 +51,6 @@ import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository; import mage.cards.repository.CardRepository;
import mage.cards.repository.ExpansionInfo; import mage.cards.repository.ExpansionInfo;
import mage.cards.repository.ExpansionRepository; import mage.cards.repository.ExpansionRepository;
import mage.cards.repository.RepositoryUtil;
import mage.constants.Constants.SessionState; import mage.constants.Constants.SessionState;
import mage.constants.ManaType; import mage.constants.ManaType;
import mage.constants.PlayerAction; import mage.constants.PlayerAction;
@ -76,6 +77,7 @@ import org.jboss.remoting.CannotConnectException;
import org.jboss.remoting.Client; import org.jboss.remoting.Client;
import org.jboss.remoting.ConnectionListener; import org.jboss.remoting.ConnectionListener;
import org.jboss.remoting.ConnectionValidator; import org.jboss.remoting.ConnectionValidator;
import org.jboss.remoting.InvocationFailureException;
import org.jboss.remoting.InvokerLocator; import org.jboss.remoting.InvokerLocator;
import org.jboss.remoting.Remoting; import org.jboss.remoting.Remoting;
import org.jboss.remoting.callback.Callback; import org.jboss.remoting.callback.Callback;
@ -299,6 +301,27 @@ public class SessionImpl implements Session {
} catch (MalformedURLException ex) { } catch (MalformedURLException ex) {
logger.fatal("", ex); logger.fatal("", ex);
client.showMessage("Unable to connect to server. " + ex.getMessage()); client.showMessage("Unable to connect to server. " + ex.getMessage());
} catch (UndeclaredThrowableException ex) {
String addMessage = "";
if (ex.getCause() instanceof InvocationFailureException) {
InvocationFailureException exep = (InvocationFailureException) ex.getCause();
if (exep.getCause() instanceof IOException) {
if (exep.getCause().getMessage().startsWith("Field hash null is not available on current")) {
addMessage = "Probabaly the server version is not compatible to the client. ";
}
}
}
if (addMessage.isEmpty()) {
logger.fatal("", ex);
}
client.showMessage("Unable to connect to server. " + addMessage + (ex.getMessage() != null ? ex.getMessage():""));
} catch (IOException ex) {
logger.fatal("", ex);
String addMessage = "";
if (ex.getMessage() != null && ex.getMessage().startsWith("Unable to perform invocation")) {
addMessage = "Maybe the server version is not compatible. ";
}
client.showMessage("Unable to connect to server. " + addMessage + ex.getMessage() != null ? ex.getMessage():"");
} catch (MageVersionException ex) { } catch (MageVersionException ex) {
if (!canceled) { if (!canceled) {
client.showMessage("Unable to connect to server. " + ex.getMessage()); client.showMessage("Unable to connect to server. " + ex.getMessage());
@ -1418,7 +1441,11 @@ public class SessionImpl implements Session {
@Override @Override
public String getVersionInfo() { public String getVersionInfo() {
if (serverState != null) {
return serverState.getVersion().toString(); return serverState.getVersion().toString();
} else {
return "<no server state>";
}
} }
} }