Adding statusCode from AppsmithPluginErrors when plugins error out
This ensures that we can always display a status code on the client.
This commit is contained in:
parent
a569156029
commit
9f82bde92c
6
app/server/.gitignore
vendored
6
app/server/.gitignore
vendored
|
|
@ -4,3 +4,9 @@ target/**
|
||||||
**/.idea
|
**/.idea
|
||||||
**/target
|
**/target
|
||||||
**/dist
|
**/dist
|
||||||
|
.settings/**
|
||||||
|
**/.settings
|
||||||
|
**/.classpath
|
||||||
|
**/.project
|
||||||
|
**/.factorypath
|
||||||
|
**.iml
|
||||||
|
|
@ -79,7 +79,7 @@ public class AclService {
|
||||||
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
WebClient.RequestHeadersSpec<?> request = webClient.post().syncBody(requestBody.toString());
|
WebClient.RequestHeadersSpec<?> request = webClient.post().bodyValue(requestBody.toString());
|
||||||
return request.retrieve().bodyToMono(OpaResponse.class);
|
return request.retrieve().bodyToMono(OpaResponse.class);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import lombok.ToString;
|
||||||
import org.springframework.data.annotation.Transient;
|
import org.springframework.data.annotation.Transient;
|
||||||
import org.springframework.data.mongodb.core.mapping.Document;
|
import org.springframework.data.mongodb.core.mapping.Document;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
|
|
@ -35,6 +36,11 @@ public class Action extends BaseDomain {
|
||||||
|
|
||||||
Boolean executeOnLoad;
|
Boolean executeOnLoad;
|
||||||
|
|
||||||
|
/* This is a list of fields specified by the client to signify which fields have dynamic bindings in them.
|
||||||
|
TODO: The server can use this field to simplify our Mustache substitutions in the future
|
||||||
|
*/
|
||||||
|
Map<String, Boolean> dynamicBindings;
|
||||||
|
|
||||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||||
Boolean isValid;
|
Boolean isValid;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ import com.appsmith.external.models.PaginationType;
|
||||||
import com.appsmith.external.models.Param;
|
import com.appsmith.external.models.Param;
|
||||||
import com.appsmith.external.models.Property;
|
import com.appsmith.external.models.Property;
|
||||||
import com.appsmith.external.models.Provider;
|
import com.appsmith.external.models.Provider;
|
||||||
|
import com.appsmith.external.pluginExceptions.AppsmithPluginError;
|
||||||
|
import com.appsmith.external.pluginExceptions.AppsmithPluginException;
|
||||||
import com.appsmith.external.plugins.PluginExecutor;
|
import com.appsmith.external.plugins.PluginExecutor;
|
||||||
import com.appsmith.server.constants.AnalyticsEvents;
|
import com.appsmith.server.constants.AnalyticsEvents;
|
||||||
import com.appsmith.server.constants.FieldName;
|
import com.appsmith.server.constants.FieldName;
|
||||||
|
|
@ -432,6 +434,12 @@ public class ActionServiceImpl extends BaseService<ActionRepository, Action, Str
|
||||||
ActionExecutionResult result = new ActionExecutionResult();
|
ActionExecutionResult result = new ActionExecutionResult();
|
||||||
result.setBody(e.getMessage());
|
result.setBody(e.getMessage());
|
||||||
result.setIsExecutionSuccess(false);
|
result.setIsExecutionSuccess(false);
|
||||||
|
// Set the status code for Appsmith plugin errors
|
||||||
|
if (e instanceof AppsmithPluginException) {
|
||||||
|
result.setStatusCode(((AppsmithPluginException) e).getAppErrorCode().toString());
|
||||||
|
} else {
|
||||||
|
result.setStatusCode(AppsmithPluginError.PLUGIN_ERROR.getAppErrorCode().toString());
|
||||||
|
}
|
||||||
return Mono.just(result);
|
return Mono.just(result);
|
||||||
})
|
})
|
||||||
.map(obj -> populateRequestFields(actionConfiguration, (ActionExecutionResult) obj));
|
.map(obj -> populateRequestFields(actionConfiguration, (ActionExecutionResult) obj));
|
||||||
|
|
|
||||||
|
|
@ -203,7 +203,7 @@ public class MarketplaceServiceImpl implements MarketplaceService {
|
||||||
|
|
||||||
if (params != null) {
|
if (params != null) {
|
||||||
for (String key : params.keySet()) {
|
for (String key : params.keySet()) {
|
||||||
uriBuilder.queryParam(key, URLEncoder.encode(params.getFirst(key)));
|
uriBuilder.queryParam(key, URLEncoder.encode(params.getFirst(key), StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ package com.appsmith.server.services;
|
||||||
import com.appsmith.external.models.ActionConfiguration;
|
import com.appsmith.external.models.ActionConfiguration;
|
||||||
import com.appsmith.external.models.ActionExecutionResult;
|
import com.appsmith.external.models.ActionExecutionResult;
|
||||||
import com.appsmith.external.models.Property;
|
import com.appsmith.external.models.Property;
|
||||||
|
import com.appsmith.external.pluginExceptions.AppsmithPluginError;
|
||||||
|
import com.appsmith.external.pluginExceptions.AppsmithPluginException;
|
||||||
import com.appsmith.external.plugins.PluginExecutor;
|
import com.appsmith.external.plugins.PluginExecutor;
|
||||||
import com.appsmith.server.constants.FieldName;
|
import com.appsmith.server.constants.FieldName;
|
||||||
import com.appsmith.server.domains.Action;
|
import com.appsmith.server.domains.Action;
|
||||||
|
|
@ -301,6 +303,39 @@ public class ActionServiceTest {
|
||||||
.verifyComplete();
|
.verifyComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@WithUserDetails(value = "api_user")
|
||||||
|
public void testActionExecuteErrorResponse() {
|
||||||
|
ActionExecutionResult mockResult = new ActionExecutionResult();
|
||||||
|
mockResult.setIsExecutionSuccess(true);
|
||||||
|
mockResult.setBody("response-body");
|
||||||
|
|
||||||
|
Action action = new Action();
|
||||||
|
ActionConfiguration actionConfiguration = new ActionConfiguration();
|
||||||
|
actionConfiguration.setHeaders(List.of(
|
||||||
|
new Property("random-header-key", "random-header-value"),
|
||||||
|
new Property("", "")
|
||||||
|
));
|
||||||
|
action.setActionConfiguration(actionConfiguration);
|
||||||
|
|
||||||
|
ExecuteActionDTO executeActionDTO = new ExecuteActionDTO();
|
||||||
|
executeActionDTO.setAction(action);
|
||||||
|
|
||||||
|
AppsmithPluginException pluginException = new AppsmithPluginException(AppsmithPluginError.PLUGIN_ERROR);
|
||||||
|
Mockito.when(pluginExecutorHelper.getPluginExecutor(Mockito.any())).thenReturn(Mono.just(pluginExecutor));
|
||||||
|
Mockito.when(pluginExecutor.execute(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(Mono.error(pluginException));
|
||||||
|
Mockito.when(pluginExecutor.datasourceCreate(Mockito.any())).thenReturn(Mono.empty());
|
||||||
|
|
||||||
|
Mono<ActionExecutionResult> executionResultMono = actionService.executeAction(executeActionDTO);
|
||||||
|
|
||||||
|
StepVerifier.create(executionResultMono)
|
||||||
|
.assertNext(result -> {
|
||||||
|
assertThat(result.getIsExecutionSuccess()).isFalse();
|
||||||
|
assertThat(result.getStatusCode()).isEqualTo(pluginException.getAppErrorCode().toString());
|
||||||
|
})
|
||||||
|
.verifyComplete();
|
||||||
|
}
|
||||||
|
|
||||||
private void executeAndAssertAction(ExecuteActionDTO executeActionDTO, ActionConfiguration actionConfiguration, ActionExecutionResult mockResult) {
|
private void executeAndAssertAction(ExecuteActionDTO executeActionDTO, ActionConfiguration actionConfiguration, ActionExecutionResult mockResult) {
|
||||||
|
|
||||||
Mono<ActionExecutionResult> actionExecutionResultMono = executeAction(executeActionDTO, actionConfiguration, mockResult);
|
Mono<ActionExecutionResult> actionExecutionResultMono = executeAction(executeActionDTO, actionConfiguration, mockResult);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user