Report error when cURL command is invalid.

This commit is contained in:
Shrikant Kandula 2020-05-12 04:12:55 +00:00 committed by Arpit Mohan
parent 0e2320895c
commit 7f4d32e7d4
3 changed files with 10 additions and 5 deletions

View File

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

View File

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

View File

@ -517,7 +517,7 @@ public class CurlImporterServiceTest {
StepVerifier
.create(actionMono)
.verifyComplete();
.verifyError();
}
// Assertion utilities for working with Action assertions.