Skip to content
Snippets Groups Projects
Commit 736d0ce7 authored by Syed OMAR's avatar Syed OMAR
Browse files

Added error handling for deleting services

parent 7d0d11da
No related branches found
No related tags found
No related merge requests found
Pipeline #8322 canceled
......@@ -54,21 +54,40 @@ public class DeleteServiceSceneController {
if (username.equals(confirmUser)) {
try {
DataStorage ds = new DataStorage("master_login.json");
// Check if the service exists
Data existingData = ds.getData(platform, username);
if (existingData == null) {
// If the service doesn't exist, show error alert
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Delete Service");
alert.setHeaderText("Error");
alert.setContentText("No service found with the provided platform and username.");
alert.showAndWait();
return; // Exit method early if service doesn't exist
}
// If service exists, proceed with deletion
ds.deleteData(platform, username);
ds.saveToJSON();
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Delete Service");
alert.setHeaderText("Success");
alert.setContentText("Service deleted successfully.");
alert.showAndWait();
// Reload the main page
Parent root = FXMLLoader.load(getClass().getResource("MainPage.fxml"));
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
stage.setScene(new Scene(root));
stage.show();
} catch (Exception e) {
e.printStackTrace();
}
} else {
// If username does not match the confirm username field
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Delete Service");
alert.setHeaderText("Error");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment