Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,11 @@ public class ErrorPayload {

private ErrorDictionary code;

private String subCode;

private String description;

public ErrorPayload(final ErrorDictionary code, final String description) {
this(code, null, description);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import javax.ws.rs.core.Response;

import org.talend.sdk.component.api.exception.ComponentException;
import org.talend.sdk.component.api.exception.ComponentException.ErrorOrigin;
import org.talend.sdk.component.api.exception.DiscoverSchemaException;
import org.talend.sdk.component.runtime.manager.ComponentManager;
import org.talend.sdk.component.runtime.manager.ContainerComponentRegistry;
import org.talend.sdk.component.runtime.manager.ServiceMeta;
Expand Down Expand Up @@ -212,29 +214,34 @@ private CompletableFuture<Response> doExecuteLocalAction(final String family, fi

private Response onError(final Throwable re) {
log.warn(re.getMessage(), re);
if (WebApplicationException.class.isInstance(re.getCause())) {
return WebApplicationException.class.cast(re.getCause()).getResponse();
if (re.getCause() instanceof WebApplicationException webException) {
return webException.getResponse();
}

if (ComponentException.class.isInstance(re)) {
final ComponentException ce = (ComponentException) re;
final String description = "Action execution failed with: " + ofNullable(re.getMessage())
.orElseGet(() -> re instanceof NullPointerException
? "unexpected null"
: "no error message");
if (re instanceof final DiscoverSchemaException eSchema) {
// we send reason to recognize the error on client side
final String subCode = eSchema.getPossibleHandleErrorWith().toString();
throw new WebApplicationException(Response
.status(ce.getErrorOrigin() == ComponentException.ErrorOrigin.USER ? 400
: ce.getErrorOrigin() == ComponentException.ErrorOrigin.BACKEND ? 456 : 520,
.status(400, subCode)
.entity(new ErrorPayload(ErrorDictionary.ACTION_ERROR, subCode, description))
.build());
} else if (re instanceof final ComponentException eComponent) {
throw new WebApplicationException(Response
.status(eComponent.getErrorOrigin() == ErrorOrigin.USER
? 400
: eComponent.getErrorOrigin() == ErrorOrigin.BACKEND ? 456 : 520,
"Unexpected callback error")
.entity(new ErrorPayload(ErrorDictionary.ACTION_ERROR,
"Action execution failed with: " + ofNullable(re.getMessage())
.orElseGet(() -> NullPointerException.class.isInstance(re) ? "unexpected null"
: "no error message")))
.entity(new ErrorPayload(ErrorDictionary.ACTION_ERROR, description))
.build());
}

throw new WebApplicationException(Response
.status(520, "Unexpected callback error")
.entity(new ErrorPayload(ErrorDictionary.ACTION_ERROR,
"Action execution failed with: " + ofNullable(re.getMessage())
.orElseGet(() -> NullPointerException.class.isInstance(re) ? "unexpected null"
: "no error message")))
.entity(new ErrorPayload(ErrorDictionary.ACTION_ERROR, description))
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import javax.inject.Inject;
import javax.json.bind.Jsonb;

import org.talend.sdk.component.api.record.Schema;
import org.talend.sdk.component.runtime.internationalization.ParameterBundle;
import org.talend.sdk.component.runtime.manager.ParameterMeta;
import org.talend.sdk.component.runtime.manager.reflect.parameterenricher.ValidationParameterEnricher;
Expand Down Expand Up @@ -94,6 +95,9 @@ private Stream<SimplePropertyDefinition> buildProperties(final List<ParameterMet
} else {
metadata = ofNullable(sanitizedMetadata).orElseGet(HashMap::new);
metadata.put("definition::parameter::index", String.valueOf(meta.indexOf(p)));
if (p.getJavaType() instanceof Class clazzType && Schema.class.isAssignableFrom(clazzType)) {
metadata.put("definition::parameter::schema", "");
}
}
final DefaultValueInspector.Instance instance = defaultValueInspector
.createDemoInstance(
Expand Down
Loading
Loading