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
This commit is contained in:
Nayan 2023-09-27 19:10:57 +06:00 committed by GitHub
parent ab91125748
commit b399d747ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View File

@ -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();

View File

@ -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