use of org.mule.runtime.api.message.Error in project mule by mulesoft.
the class DataWeaveExpressionLanguageAdaptorTestCase method fullErrorBinding.
@Test
public void fullErrorBinding() throws Exception {
String description = "An error occurred";
String detailedDescription = "A division by zero has collapsed our systems.";
String exceptionMessage = "dividend cannot be zero";
String errorId = "WEAVE_TEST";
ErrorType errorType = mock(ErrorType.class);
when(errorType.getIdentifier()).thenReturn(errorId);
Error error = ErrorBuilder.builder().description(description).detailedDescription(detailedDescription).exception(new IllegalArgumentException(exceptionMessage)).errorType(errorType).build();
Optional opt = Optional.of(error);
CoreEvent event = getEventWithError(opt);
doReturn(testEvent().getMessage()).when(event).getMessage();
String expression = "'$(error.description) $(error.detailedDescription) $(error.cause.message) $(error.errorType.identifier)'";
TypedValue result = expressionLanguage.evaluate(expression, event, BindingContext.builder().build());
assertThat(result.getValue(), is(format("%s %s %s %s", description, detailedDescription, exceptionMessage, errorId)));
}
use of org.mule.runtime.api.message.Error in project mule by mulesoft.
the class MessagingExceptionResolverTestCase method resolveWithAnEventThatCarriesError.
@Test
public void resolveWithAnEventThatCarriesError() {
Optional<Error> surfaceError = mockError(TRANSFORMER, null);
when(event.getError()).thenReturn(surfaceError);
MessagingException me = newMessagingException(new Exception(), event, processor);
MessagingException resolved = resolver.resolve(me, context);
assertExceptionErrorType(resolved, TRANSFORMER);
assertExceptionMessage(resolved.getMessage(), ERROR_MESSAGE);
}
use of org.mule.runtime.api.message.Error in project mule by mulesoft.
the class MessagingExceptionResolverTestCase method mockError.
private Optional<Error> mockError(ErrorType errorType, Throwable cause) {
Error error = mock(Error.class);
when(error.getErrorType()).thenReturn(errorType);
when(error.getCause()).thenReturn(cause);
return Optional.of(error);
}
use of org.mule.runtime.api.message.Error in project mule by mulesoft.
the class MessagingExceptionResolverTestCase method resolveWithParentInChain.
@Test
public void resolveWithParentInChain() {
ErrorType withParent = ErrorTypeBuilder.builder().parentErrorType(CONNECTION).identifier("CONNECT").namespace("TEST").build();
Optional<Error> surfaceError = mockError(withParent, new Exception());
when(event.getError()).thenReturn(surfaceError);
Exception cause = new ConnectionException("Some Connection Error", new Exception());
MessagingException me = newMessagingException(cause, event, processor);
MessagingException resolved = resolver.resolve(me, context);
assertExceptionErrorType(resolved, withParent);
assertExceptionMessage(resolved.getMessage(), ERROR_MESSAGE);
}
use of org.mule.runtime.api.message.Error in project mule by mulesoft.
the class InternalExceptionUtils method getErrorFromFailingProcessor.
/**
* Determine the {@link ErrorType} of a given exception thrown by a given message processor.
*
* @param processor the component that threw the exception (processor or source).
* @param cause the exception thrown.
* @param locator the {@link ErrorTypeLocator}.
* @return the resolved {@link ErrorType}
*/
public static Error getErrorFromFailingProcessor(CoreEvent currentEvent, Component processor, Throwable cause, ErrorTypeLocator locator) {
ErrorType currentError = currentEvent != null ? currentEvent.getError().map(Error::getErrorType).orElse(null) : null;
ErrorType foundErrorType = locator.lookupErrorType(cause);
ErrorType resultError = isUnknownMuleError(foundErrorType) ? currentError : foundErrorType;
ErrorType errorType = getComponentIdentifier(processor).map(ci -> locator.lookupComponentErrorType(ci, cause)).orElse(locator.lookupErrorType(cause));
return ErrorBuilder.builder(cause).errorType(getErrorMappings(processor).stream().filter(m -> m.match(resultError == null || isUnknownMuleError(resultError) ? errorType : currentError)).findFirst().map(ErrorMapping::getTarget).orElse(errorType)).build();
}
Aggregations