use of org.mule.runtime.api.message.ErrorType in project mule by mulesoft.
the class DefaultErrorTypeRepository method addInternalErrorType.
/**
* {@inheritDoc}
*/
@Override
public ErrorType addInternalErrorType(ComponentIdentifier errorTypeIdentifier, ErrorType parentErrorType) {
ErrorType errorType = buildErrorType(errorTypeIdentifier, parentErrorType);
internalErrorTypes.put(errorTypeIdentifier, errorType);
return errorType;
}
use of org.mule.runtime.api.message.ErrorType in project mule by mulesoft.
the class BeanDefinitionFactory method resolveErrorType.
private ErrorType resolveErrorType(String representation) {
int separator = representation.indexOf(":");
String namespace;
String identifier;
if (separator > 0) {
namespace = representation.substring(0, separator).toUpperCase();
identifier = representation.substring(separator + 1).toUpperCase();
} else {
namespace = CORE_ERROR_NS;
identifier = representation.toUpperCase();
}
ComponentIdentifier errorIdentifier = ComponentIdentifier.builder().namespace(namespace).name(identifier).build();
if (CORE_ERROR_NS.equals(namespace)) {
return errorTypeRepository.lookupErrorType(errorIdentifier).orElseThrow(() -> new MuleRuntimeException(createStaticMessage(format("There's no MULE error named '%s'.", identifier))));
} else if (errorTypeRepository.getErrorNamespaces().contains(namespace) && !syntheticErrorNamespaces.contains(namespace)) {
throw new MuleRuntimeException(createStaticMessage(format("Cannot use error type '%s:%s': namespace already exists.", namespace, identifier)));
} else if (syntheticErrorNamespaces.contains(namespace)) {
Optional<ErrorType> optionalErrorType = errorTypeRepository.lookupErrorType(errorIdentifier);
if (optionalErrorType.isPresent()) {
return optionalErrorType.get();
}
} else {
syntheticErrorNamespaces.add(namespace);
}
return errorTypeRepository.addErrorType(errorIdentifier, errorTypeRepository.getAnyErrorType());
}
use of org.mule.runtime.api.message.ErrorType in project mule by mulesoft.
the class ThrowProcessor method process.
@Override
public CoreEvent process(CoreEvent event) throws MuleException {
if (count == -1 || count-- > 0) {
try {
Throwable instantiatedException = exception.newInstance();
if (error != null) {
ErrorTypeRepository errorTypeRepository = muleContext.getErrorTypeRepository();
ErrorType errorType = errorTypeRepository.lookupErrorType(buildFromStringRepresentation(error)).orElseThrow(() -> new DefaultMuleException(format("Could not find error: '%s'", error)));
throw new TypedException(instantiatedException, errorType);
} else {
checkArgument(instantiatedException instanceof TypedException, EXCEPTION_ERROR);
throw (TypedException) instantiatedException;
}
} catch (InstantiationException | IllegalAccessException e) {
throw new DefaultMuleException(format("Failed to instantiate exception class '%s'", exception.getSimpleName()));
}
} else {
return event;
}
}
use of org.mule.runtime.api.message.ErrorType in project mule by mulesoft.
the class DataWeaveExpressionLanguageAdaptorTestCase method childErrorsErrorBinding.
@Test
public void childErrorsErrorBinding() throws Exception {
String childErrorMessage = "error";
String otherChildErrorMessage = "oops";
ErrorType errorType = mock(ErrorType.class);
Error error = mock(Error.class);
when(error.getChildErrors()).thenReturn(asList(ErrorBuilder.builder(new IOException(childErrorMessage)).errorType(errorType).build(), ErrorBuilder.builder(new DefaultMuleException(otherChildErrorMessage)).errorType(errorType).build()));
Optional opt = Optional.of(error);
CoreEvent event = getEventWithError(opt);
doReturn(testEvent().getMessage()).when(event).getMessage();
String expression = "error.childErrors reduce ((child, acc = '') -> acc ++ child.cause.message)";
TypedValue result = expressionLanguage.evaluate(expression, event, BindingContext.builder().build());
assertThat(result.getValue(), is(format("%s%s", childErrorMessage, otherChildErrorMessage)));
}
use of org.mule.runtime.api.message.ErrorType in project mule by mulesoft.
the class OnCriticalErrorHandlerTestCase method acceptsCriticalChild.
@Test
public void acceptsCriticalChild() {
ErrorType errorType = mock(ErrorType.class);
when(error.getErrorType()).thenReturn(errorType);
when(errorType.getParentErrorType()).thenReturn(CRITICAL_ERROR_TYPE);
assertThat(handler.accept(muleEvent), is(true));
}
Aggregations