From 7f4d32e7d4e080a0e3ad8114613004cfb92b7215 Mon Sep 17 00:00:00 2001 From: Shrikant Kandula Date: Tue, 12 May 2020 04:12:55 +0000 Subject: [PATCH] Report error when cURL command is invalid. --- .../com/appsmith/server/exceptions/AppsmithError.java | 4 +++- .../appsmith/server/services/CurlImporterService.java | 9 ++++++--- .../server/services/CurlImporterServiceTest.java | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java index fd089e2a3e..b3d7621887 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java @@ -35,13 +35,15 @@ public enum AppsmithError { INVALID_DATASOURCE_NAME(400, 4026, "Invalid datasource name. Check again."), NO_RESOURCE_FOUND(404, 4027, "Unable to find {0} with id {1}"), GENERIC_BAD_REQUEST(400, 4028, "Bad Request: {0}"), + INVALID_CURL_COMMAND(400, 4029, "Invalid cURL command, couldn't import."), INTERNAL_SERVER_ERROR(500, 5000, "Internal server error while processing request"), REPOSITORY_SAVE_FAILED(500, 5001, "Failed to save the repository. Try again."), PLUGIN_INSTALLATION_FAILED_DOWNLOAD_ERROR(500, 5002, "Plugin installation failed due to an error while downloading it. Check the jar location & try again."), PLUGIN_RUN_FAILED(500, 5003, "Plugin execution failed with error {0}"), PLUGIN_EXECUTION_TIMEOUT(504, 5040, "Plugin Execution exceeded the maximum allowed time. Please increase the timeout in your action settings or check your backend action endpoint"), PLUGIN_LOAD_FORM_JSON_FAIL(500, 5004, "Unable to load datasource form configuration. Details: {0}."), - MARKETPLACE_TIMEOUT(504, 5041, "Marketplace is responding too slowly. Please try again later"); + MARKETPLACE_TIMEOUT(504, 5041, "Marketplace is responding too slowly. Please try again later"), + ; private Integer httpErrorCode; diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/CurlImporterService.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/CurlImporterService.java index 12c570923c..fe238787ed 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/CurlImporterService.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/CurlImporterService.java @@ -5,6 +5,8 @@ import com.appsmith.external.models.DatasourceConfiguration; import com.appsmith.external.models.Property; import com.appsmith.server.domains.Action; import com.appsmith.server.domains.Datasource; +import com.appsmith.server.exceptions.AppsmithError; +import com.appsmith.server.exceptions.AppsmithException; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.apache.http.NameValuePair; @@ -48,13 +50,14 @@ public class CurlImporterService extends BaseApiImporter { public Mono importAction(Object input, String pageId, String name) { Action action = curlToAction((String) input, pageId, name); + if (action == null) { + return Mono.error(new AppsmithException(AppsmithError.INVALID_CURL_COMMAND)); + } + // Set the default values for datasource (plugin, name) and then create the action // with embedded datasource return pluginService.findByPackageName(RESTAPI_PLUGIN) .flatMap(plugin -> { - if (action == null) { - return Mono.empty(); - } final Datasource datasource = action.getDatasource(); final DatasourceConfiguration datasourceConfiguration = datasource.getDatasourceConfiguration(); datasource.setName(datasourceConfiguration.getUrl()); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/CurlImporterServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/CurlImporterServiceTest.java index ce7ce75b23..c107c61655 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/CurlImporterServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/CurlImporterServiceTest.java @@ -517,7 +517,7 @@ public class CurlImporterServiceTest { StepVerifier .create(actionMono) - .verifyComplete(); + .verifyError(); } // Assertion utilities for working with Action assertions.