Search in sources :

Example 1 with UiActionResult

use of org.talend.sdk.component.form.model.UiActionResult in project component-runtime by Talend.

the class ActionService method map.

public UiActionResult map(final WebException exception) {
    final UiActionResult actionResult = new UiActionResult();
    actionResult.setRawData(exception.getData());
    // default error will be mapped to the calling option
    actionResult.setError(ofNullable(exception.getData()).flatMap(d -> Stream.of("description", "comment").map(d::get).filter(Objects::nonNull).findFirst()).map(String::valueOf).orElse(exception.getMessage()));
    return actionResult;
}
Also used : Objects(java.util.Objects) Stream(java.util.stream.Stream) UiActionResult(org.talend.sdk.component.form.model.UiActionResult) Optional.ofNullable(java.util.Optional.ofNullable) Map(java.util.Map) UiActionResult(org.talend.sdk.component.form.model.UiActionResult)

Example 2 with UiActionResult

use of org.talend.sdk.component.form.model.UiActionResult in project component-runtime by Talend.

the class WebAppComponentProxy method onException.

private void onException(final AsyncResponse response, final Throwable e) {
    final UiActionResult payload;
    final int status;
    if (WebException.class.isInstance(e)) {
        final WebException we = WebException.class.cast(e);
        status = we.getStatus();
        payload = actionService.map(we);
    } else if (CompletionException.class.isInstance(e)) {
        final CompletionException actualException = CompletionException.class.cast(e);
        log.error(actualException.getMessage(), actualException);
        status = Response.Status.BAD_GATEWAY.getStatusCode();
        payload = actionService.map(new WebException(actualException, -1, emptyMap()));
    } else {
        log.error(e.getMessage(), e);
        status = Response.Status.BAD_GATEWAY.getStatusCode();
        payload = actionService.map(new WebException(e, -1, emptyMap()));
    }
    response.resume(new WebApplicationException(Response.status(status).entity(payload).build()));
}
Also used : WebException(org.talend.sdk.component.form.api.WebException) WebApplicationException(javax.ws.rs.WebApplicationException) CompletionException(java.util.concurrent.CompletionException) UiActionResult(org.talend.sdk.component.form.model.UiActionResult)

Aggregations

UiActionResult (org.talend.sdk.component.form.model.UiActionResult)2 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional.ofNullable (java.util.Optional.ofNullable)1 CompletionException (java.util.concurrent.CompletionException)1 Stream (java.util.stream.Stream)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 WebException (org.talend.sdk.component.form.api.WebException)1