Search in sources :

Example 21 with Error

use of org.mule.runtime.api.message.Error in project mule by mulesoft.

the class AbstractForkJoinStrategyFactory method createCompositeRoutingException.

private CompositeRoutingException createCompositeRoutingException(List<CoreEvent> results) {
    Map<String, Message> successMap = new LinkedHashMap<>();
    Map<String, Error> errorMap = new LinkedHashMap<>();
    for (CoreEvent event : results) {
        String key = Integer.toString(event.getGroupCorrelation().get().getSequence());
        if (event.getError().isPresent()) {
            errorMap.put(key, event.getError().get());
        } else {
            successMap.put(key, event.getMessage());
        }
    }
    return new CompositeRoutingException(new RoutingResult(successMap, errorMap));
}
Also used : CompositeRoutingException(org.mule.runtime.core.privileged.routing.CompositeRoutingException) RoutingResult(org.mule.runtime.core.privileged.routing.RoutingResult) Message(org.mule.runtime.api.message.Message) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Error(org.mule.runtime.api.message.Error) LinkedHashMap(java.util.LinkedHashMap)

Example 22 with Error

use of org.mule.runtime.api.message.Error in project mule by mulesoft.

the class ReactiveInterceptionAction method fail.

@Override
public CompletableFuture<InterceptionEvent> fail(Throwable cause) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Called fail() for processor {} with cause {} ({})", ((Component) processor).getLocation().getLocation(), cause.getClass(), cause.getMessage());
    }
    Error newError = getErrorFromFailingProcessor(null, (Component) processor, cause, errorTypeLocator);
    interceptionEvent.setError(newError.getErrorType(), cause);
    CompletableFuture<InterceptionEvent> completableFuture = new CompletableFuture<>();
    completableFuture.completeExceptionally(new MessagingException(interceptionEvent.resolve(), cause, (Component) processor));
    return completableFuture;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) DefaultInterceptionEvent(org.mule.runtime.core.internal.interception.DefaultInterceptionEvent) InterceptionEvent(org.mule.runtime.api.interception.InterceptionEvent) Error(org.mule.runtime.api.message.Error) Component(org.mule.runtime.api.component.Component)

Example 23 with Error

use of org.mule.runtime.api.message.Error in project mule by mulesoft.

the class InternalExceptionUtils method createErrorEvent.

/**
 * Create new {@link CoreEvent} with {@link org.mule.runtime.api.message.Error} instance set.
 *
 * @param currentEvent event when error occured.
 * @param obj message processor/source.
 * @param me messaging exception.
 * @param locator the mule context.
 * @return new {@link CoreEvent} with relevant {@link org.mule.runtime.api.message.Error} set.
 */
public static CoreEvent createErrorEvent(CoreEvent currentEvent, Component obj, MessagingException me, ErrorTypeLocator locator) {
    Throwable cause = me.getCause() != null ? me.getCause() : me;
    List<ErrorMapping> errorMappings = getErrorMappings(obj);
    if (!errorMappings.isEmpty() || isMessagingExceptionCause(me, cause)) {
        Error newError = getErrorFromFailingProcessor(currentEvent, obj, cause, locator);
        CoreEvent newEvent = CoreEvent.builder(me.getEvent()).error(newError).build();
        me.setProcessedEvent(newEvent);
        return newEvent;
    } else {
        return currentEvent;
    }
}
Also used : ErrorMapping(org.mule.runtime.core.internal.exception.ErrorMapping) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ExceptionUtils.isUnknownMuleError(org.mule.runtime.core.api.util.ExceptionUtils.isUnknownMuleError) Error(org.mule.runtime.api.message.Error)

Example 24 with Error

use of org.mule.runtime.api.message.Error in project mule by mulesoft.

the class CompositeRoutingException method getDetailedMessage.

@Override
public String getDetailedMessage() {
    StringBuilder builder = new StringBuilder();
    builder.append(MESSAGE_TITLE).append(lineSeparator());
    for (Entry<String, Error> entry : routingResult.getFailures().entrySet()) {
        String routeSubtitle = String.format("Route %s: ", entry.getKey());
        MuleException muleException = ExceptionHelper.getRootMuleException(entry.getValue().getCause());
        if (muleException != null) {
            builder.append(routeSubtitle).append(muleException.getDetailedMessage());
        } else {
            builder.append(routeSubtitle).append("Caught exception in Exception Strategy: " + entry.getValue().getCause().getMessage());
        }
    }
    return builder.toString();
}
Also used : Error(org.mule.runtime.api.message.Error) MuleException(org.mule.runtime.api.exception.MuleException)

Example 25 with Error

use of org.mule.runtime.api.message.Error in project mule by mulesoft.

the class MessagingExceptionResolverTestCase method resolveExceptionWithUnknownUnderlyingError.

@Test
public void resolveExceptionWithUnknownUnderlyingError() {
    Optional<Error> surfaceError = mockError(CONNECTION, null);
    when(event.getError()).thenReturn(surfaceError);
    MessagingException me = newMessagingException(new Exception(), event, processor);
    MessagingException resolved = resolver.resolve(me, context);
    assertExceptionErrorType(resolved, CONNECTION);
}
Also used : MessagingException(org.mule.runtime.core.internal.exception.MessagingException) Error(org.mule.runtime.api.message.Error) MuleFatalException(org.mule.runtime.api.exception.MuleFatalException) MuleException(org.mule.runtime.api.exception.MuleException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) TransformerException(org.mule.runtime.core.api.transformer.TransformerException) ConnectionException(org.mule.runtime.api.connection.ConnectionException) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

Error (org.mule.runtime.api.message.Error)30 Test (org.junit.Test)18 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)11 SmallTest (org.mule.tck.size.SmallTest)11 MuleException (org.mule.runtime.api.exception.MuleException)10 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)9 ErrorType (org.mule.runtime.api.message.ErrorType)7 Optional (java.util.Optional)6 Matchers.containsString (org.hamcrest.Matchers.containsString)5 ConnectionException (org.mule.runtime.api.connection.ConnectionException)5 MuleFatalException (org.mule.runtime.api.exception.MuleFatalException)5 TransformerException (org.mule.runtime.core.api.transformer.TransformerException)5 Component (org.mule.runtime.api.component.Component)4 TypedValue (org.mule.runtime.api.metadata.TypedValue)4 Message (org.mule.runtime.api.message.Message)3 ExceptionUtils.isUnknownMuleError (org.mule.runtime.core.api.util.ExceptionUtils.isUnknownMuleError)3 ErrorMapping (org.mule.runtime.core.internal.exception.ErrorMapping)3 List (java.util.List)2 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)2 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)2