use of org.mule.runtime.core.api.exception.SingleErrorTypeMatcher in project mule by mulesoft.
the class MessagingExceptionResolver method findRoot.
private Optional<Pair<Throwable, ErrorType>> findRoot(Component obj, MessagingException me, ErrorTypeLocator locator) {
List<Pair<Throwable, ErrorType>> errors = collectErrors(obj, me, locator);
if (errors.isEmpty()) {
return collectCritical(obj, me, locator).stream().findFirst();
}
// We look if there is a more specific error in the chain that matches with the root error (is child or has the same error)
SingleErrorTypeMatcher matcher = new SingleErrorTypeMatcher(errors.get(0).getSecond());
Reference<Pair<Throwable, ErrorType>> result = new Reference<>();
errors.forEach(p -> {
if (matcher.match(p.getSecond())) {
result.set(p);
}
});
return Optional.ofNullable(result.get());
}
use of org.mule.runtime.core.api.exception.SingleErrorTypeMatcher in project mule by mulesoft.
the class TemplateOnErrorHandler method createErrorType.
public static ErrorTypeMatcher createErrorType(ErrorTypeRepository errorTypeRepository, String errorTypeNames) {
if (errorTypeNames == null) {
return null;
}
String[] errorTypeIdentifiers = errorTypeNames.split(",");
List<ErrorTypeMatcher> matchers = stream(errorTypeIdentifiers).map((identifier) -> {
String parsedIdentifier = identifier.trim();
return new SingleErrorTypeMatcher(errorTypeRepository.lookupErrorType(buildFromStringRepresentation(parsedIdentifier)).orElseThrow(() -> new MuleRuntimeException(createStaticMessage("Could not find ErrorType for the given identifier: '%s'", parsedIdentifier))));
}).collect(toList());
return new DisjunctiveErrorTypeMatcher(matchers);
}
use of org.mule.runtime.core.api.exception.SingleErrorTypeMatcher in project mule by mulesoft.
the class SingleErrorTypeMatcherTestCase method matchChild.
@Test
public void matchChild() {
ComponentIdentifier customTransformerIdentifier = ComponentIdentifier.builder().name("custom").namespace(CORE_NAMESPACE_NAME).build();
ErrorTypeRepository errorTypeRepository = muleContext.getErrorTypeRepository();
ErrorType customTransformerErrorType = errorTypeRepository.addErrorType(customTransformerIdentifier, transformationErrorType);
ErrorTypeMatcher transformationMatcher = new SingleErrorTypeMatcher(transformationErrorType);
assertThat(transformationMatcher.match(customTransformerErrorType), is(true));
}
use of org.mule.runtime.core.api.exception.SingleErrorTypeMatcher in project mule by mulesoft.
the class SingleErrorTypeMatcherTestCase method matchEqual.
@Test
public void matchEqual() {
ErrorTypeMatcher transformationMatcher = new SingleErrorTypeMatcher(transformationErrorType);
assertThat(transformationMatcher.match(transformationErrorType), is(true));
}
use of org.mule.runtime.core.api.exception.SingleErrorTypeMatcher in project mule by mulesoft.
the class SingleErrorTypeMatcherTestCase method anyMatchsAll.
@Test
public void anyMatchsAll() {
ErrorType mockErrorType = mock(ErrorType.class);
when(mockErrorType.getParentErrorType()).thenReturn(transformationErrorType);
ErrorTypeMatcher anyMatcher = new SingleErrorTypeMatcher(anyErrorType);
assertThat(anyMatcher.match(anyErrorType), is(true));
assertThat(anyMatcher.match(transformationErrorType), is(true));
assertThat(anyMatcher.match(expressionErrorType), is(true));
assertThat(anyMatcher.match(mockErrorType), is(true));
}
Aggregations