From b399d747ab75708997e516c71269b742d76443a9 Mon Sep 17 00:00:00 2001 From: Nayan Date: Wed, 27 Sep 2023 19:10:57 +0600 Subject: [PATCH] fix: Changed error message during import when fields are missing in the JSON (#27582) ## Description Instead of throwing 404, this PR informs the user which field is missing in the JSON. #### PR fixes following issue(s) Fixes #20493 --- .../ce/ImportExportApplicationServiceCEImpl.java | 5 +++-- .../solutions/ImportExportApplicationServiceTests.java | 10 ++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ImportExportApplicationServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ImportExportApplicationServiceCEImpl.java index 428a1da88f..e9d88fd0c6 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ImportExportApplicationServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ImportExportApplicationServiceCEImpl.java @@ -954,7 +954,7 @@ public class ImportExportApplicationServiceCEImpl implements ImportExportApplica private String validateApplicationJson(ApplicationJson importedDoc) { String errorField = ""; if (CollectionUtils.isEmpty(importedDoc.getPageList())) { - errorField = FieldName.PAGES; + errorField = FieldName.PAGE_LIST; } else if (importedDoc.getExportedApplication() == null) { errorField = FieldName.APPLICATION; } else if (importedDoc.getActionList() == null) { @@ -1835,7 +1835,8 @@ public class ImportExportApplicationServiceCEImpl implements ImportExportApplica String errorField = validateApplicationJson(importedDoc); if (!errorField.isEmpty()) { log.error("Error in importing application. Field {} is missing", errorField); - return Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, errorField, INVALID_JSON_FILE)); + return Mono.error(new AppsmithException( + AppsmithError.VALIDATION_FAILURE, "Field '" + errorField + "' is missing in the JSON.")); } Application importedApplication = importedDoc.getExportedApplication(); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ImportExportApplicationServiceTests.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ImportExportApplicationServiceTests.java index 07e25034da..9c33e45d88 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ImportExportApplicationServiceTests.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ImportExportApplicationServiceTests.java @@ -842,7 +842,8 @@ public class ImportExportApplicationServiceTests { .expectErrorMatches(throwable -> throwable instanceof AppsmithException && throwable .getMessage() - .equals(AppsmithError.NO_RESOURCE_FOUND.getMessage(FieldName.PAGES, INVALID_JSON_FILE))) + .equals(AppsmithError.VALIDATION_FAILURE.getMessage( + "Field '" + FieldName.PAGE_LIST + "' is missing in the JSON."))) .verify(); } @@ -858,8 +859,8 @@ public class ImportExportApplicationServiceTests { .expectErrorMatches(throwable -> throwable instanceof AppsmithException && throwable .getMessage() - .equals(AppsmithError.NO_RESOURCE_FOUND.getMessage( - FieldName.APPLICATION, INVALID_JSON_FILE))) + .equals(AppsmithError.VALIDATION_FAILURE.getMessage( + "Field '" + FieldName.APPLICATION + "' is missing in the JSON."))) .verify(); } @@ -4198,7 +4199,8 @@ public class ImportExportApplicationServiceTests { .expectErrorMatches(throwable -> throwable instanceof AppsmithException && throwable .getMessage() - .equals(AppsmithError.NO_RESOURCE_FOUND.getMessage(FieldName.PAGES, INVALID_JSON_FILE))) + .equals(AppsmithError.VALIDATION_FAILURE.getMessage( + "Field '" + FieldName.PAGE_LIST + "' is missing in the JSON."))) .verify(); // Verify that the app card is not created