Archived
1
0
Fork 0

Fix invalid connection exception

This commit is contained in:
Ziedelth 2022-01-19 11:53:36 +01:00
parent 7ac2b05254
commit 1289ac8ad5
2 changed files with 21 additions and 4 deletions

View file

@ -7,7 +7,9 @@ import fr.univ.lyon1.common.ServerConfiguration;
import fr.univ.lyon1.common.command.Command;
import fr.univ.lyon1.common.command.CommandType;
import fr.univ.lyon1.common.exception.ChatException;
import fr.univ.lyon1.common.exception.LoginInvalid;
import fr.univ.lyon1.common.exception.UnknownCommand;
import fr.univ.lyon1.gui.handlers.ServerConfigurationHandler;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.TextArea;
@ -17,6 +19,7 @@ import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;
import javafx.stage.Stage;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -135,10 +138,25 @@ public class ApplicationController {
}
}
}
} else if (object instanceof LoginInvalid) {
// TODO: Invalid login
Platform.runLater(() -> {
try {
this.closeSocket();
@NotNull
final Stage stage = (Stage) this.vboxChannelsList.getScene().getWindow();
new ServerConfigurationHandler().launch(stage);
} catch (IOException e) {
e.printStackTrace();
}
});
} else if (object instanceof ChatException) {
System.out.println("?");
((ChatException) object).printStackTrace();
} else
} else {
this.sendObject(new UnknownCommand());
}
} else {
try {
this.closeSocket();
@ -156,8 +174,6 @@ public class ApplicationController {
ex.printStackTrace();
}
}
e.printStackTrace();
}
}
});

View file

@ -122,7 +122,8 @@ public class ConnectedClient implements Runnable {
actionCommand((Command) data);
else
throw new UnknownCommand();
} catch (ChatException e) {
} catch (IOException | ChatException e) {
System.out.println("Error server " + e.getLocalizedMessage());
out.writeObject(e);
out.flush();
}