Search in sources :

Example 21 with ErrorType

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

the class DisjunctiveErrorTypeMatcherTestCase method allMatch.

@Test
public void allMatch() {
    ErrorType mockErrorType = mock(ErrorType.class);
    when(mockErrorType.getParentErrorType()).thenReturn(transformationErrorType);
    ErrorTypeMatcher matcherWithTwoTransformation = createMatcher(transformationErrorType, mockErrorType);
    assertThat(matcherWithTwoTransformation.match(mockErrorType), is(true));
}
Also used : ErrorType(org.mule.runtime.api.message.ErrorType) DisjunctiveErrorTypeMatcher(org.mule.runtime.core.api.exception.DisjunctiveErrorTypeMatcher) ErrorTypeMatcher(org.mule.runtime.core.api.exception.ErrorTypeMatcher) SingleErrorTypeMatcher(org.mule.runtime.core.api.exception.SingleErrorTypeMatcher) Test(org.junit.Test)

Example 22 with ErrorType

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

the class DefaultErrorTypeRepository method addErrorType.

/**
 * {@inheritDoc}
 */
@Override
public ErrorType addErrorType(ComponentIdentifier errorTypeIdentifier, ErrorType parentErrorType) {
    ErrorType errorType = buildErrorType(errorTypeIdentifier, parentErrorType);
    errorTypes.put(errorTypeIdentifier, errorType);
    return errorType;
}
Also used : ErrorType(org.mule.runtime.api.message.ErrorType)

Example 23 with ErrorType

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

the class ErrorTypeRepositoryFactory method createDefaultErrorTypeRepository.

/**
 * Creates the default {@link ErrorTypeRepository} to use in mule.
 * <p>
 * The {@link ErrorTypeRepository} gets populated with the default mappings between common core exceptions and core error types.
 *
 * @return a new {@link ErrorTypeRepository}.
 */
public static ErrorTypeRepository createDefaultErrorTypeRepository() {
    ErrorTypeRepository errorTypeRepository = new DefaultErrorTypeRepository();
    errorTypeRepository.addErrorType(TRANSFORMATION, errorTypeRepository.getAnyErrorType());
    errorTypeRepository.addErrorType(EXPRESSION, errorTypeRepository.getAnyErrorType());
    final ErrorType validationErrorType = errorTypeRepository.addErrorType(VALIDATION, errorTypeRepository.getAnyErrorType());
    errorTypeRepository.addErrorType(DUPLICATE_MESSAGE, validationErrorType);
    errorTypeRepository.addErrorType(REDELIVERY_EXHAUSTED, errorTypeRepository.getAnyErrorType());
    final ErrorType connectivityErrorType = errorTypeRepository.addErrorType(CONNECTIVITY, errorTypeRepository.getAnyErrorType());
    errorTypeRepository.addErrorType(RETRY_EXHAUSTED, connectivityErrorType);
    errorTypeRepository.addErrorType(ROUTING, errorTypeRepository.getAnyErrorType());
    errorTypeRepository.addErrorType(SECURITY, errorTypeRepository.getAnyErrorType());
    errorTypeRepository.addErrorType(CLIENT_SECURITY, errorTypeRepository.getErrorType(SECURITY).get());
    errorTypeRepository.addErrorType(SERVER_SECURITY, errorTypeRepository.getErrorType(SECURITY).get());
    errorTypeRepository.addErrorType(NOT_PERMITTED, errorTypeRepository.getErrorType(SERVER_SECURITY).get());
    errorTypeRepository.addErrorType(STREAM_MAXIMUM_SIZE_EXCEEDED, errorTypeRepository.getAnyErrorType());
    errorTypeRepository.addInternalErrorType(OVERLOAD, errorTypeRepository.getCriticalErrorType());
    errorTypeRepository.addInternalErrorType(FLOW_BACK_PRESSURE, errorTypeRepository.getErrorType(OVERLOAD).get());
    errorTypeRepository.addInternalErrorType(FATAL, errorTypeRepository.getCriticalErrorType());
    errorTypeRepository.addErrorType(TIMEOUT, errorTypeRepository.getAnyErrorType());
    errorTypeRepository.addErrorType(COMPOSITE_ROUTING, errorTypeRepository.getErrorType(ROUTING).get());
    final ErrorType sourceErrorType = errorTypeRepository.getSourceErrorType();
    errorTypeRepository.addErrorType(SOURCE_RESPONSE_GENERATE, errorTypeRepository.getSourceResponseErrorType());
    errorTypeRepository.addErrorType(SOURCE_RESPONSE_SEND, errorTypeRepository.getSourceResponseErrorType());
    errorTypeRepository.addInternalErrorType(SOURCE_ERROR_RESPONSE_GENERATE, sourceErrorType);
    errorTypeRepository.addInternalErrorType(SOURCE_ERROR_RESPONSE_SEND, sourceErrorType);
    return errorTypeRepository;
}
Also used : ErrorTypeRepository(org.mule.runtime.api.exception.ErrorTypeRepository) ErrorType(org.mule.runtime.api.message.ErrorType)

Example 24 with ErrorType

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

the class OnErrorContinueHandler method doInitialise.

@Override
protected void doInitialise(MuleContext muleContext) throws InitialisationException {
    super.doInitialise(muleContext);
    ErrorTypeRepository errorTypeRepository = muleContext.getErrorTypeRepository();
    sourceErrorMatcher = new SingleErrorTypeMatcher(errorTypeRepository.getSourceResponseErrorType());
    if (errorType != null) {
        String[] errors = errorType.split(",");
        for (String error : errors) {
            // Since the partial initialisation was successful, we know this error ids are safe
            String sanitizedError = error.trim();
            ErrorType errorType = errorTypeRepository.lookupErrorType(buildFromStringRepresentation(sanitizedError)).get();
            if (sourceErrorMatcher.match(errorType)) {
                throw new InitialisationException(getInitialisationError(sanitizedError), this);
            }
        }
    } else if (when == null) {
        // No error type and no expression, force ANY matcher
        errorTypeMatcher = new SingleErrorTypeMatcher(errorTypeRepository.getAnyErrorType());
    }
}
Also used : ErrorTypeRepository(org.mule.runtime.api.exception.ErrorTypeRepository) ErrorType(org.mule.runtime.api.message.ErrorType) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) SingleErrorTypeMatcher(org.mule.runtime.core.api.exception.SingleErrorTypeMatcher)

Example 25 with ErrorType

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

the class MessagingExceptionResolver method collectErrors.

private List<Pair<Throwable, ErrorType>> collectErrors(Component obj, MessagingException me, ErrorTypeLocator locator) {
    List<Pair<Throwable, ErrorType>> errors = new LinkedList<>();
    getExceptionsAsList(me).forEach(e -> {
        ErrorType type = errorTypeFromException(obj, locator, e);
        if (!isUnknownMuleError(type) && !isCriticalMuleError(type)) {
            errors.add(new Pair<>(e, type));
        }
    });
    return errors;
}
Also used : ErrorType(org.mule.runtime.api.message.ErrorType) LinkedList(java.util.LinkedList) Pair(org.mule.runtime.api.util.Pair)

Aggregations

ErrorType (org.mule.runtime.api.message.ErrorType)35 Test (org.junit.Test)19 SmallTest (org.mule.tck.size.SmallTest)9 SingleErrorTypeMatcher (org.mule.runtime.core.api.exception.SingleErrorTypeMatcher)8 Error (org.mule.runtime.api.message.Error)7 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)6 ErrorTypeMatcher (org.mule.runtime.core.api.exception.ErrorTypeMatcher)6 ErrorTypeLocator (org.mule.runtime.core.privileged.exception.ErrorTypeLocator)6 ErrorTypeRepository (org.mule.runtime.api.exception.ErrorTypeRepository)5 Optional (java.util.Optional)4 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)4 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)4 PrivilegedMuleContext (org.mule.runtime.core.privileged.PrivilegedMuleContext)4 LinkedList (java.util.LinkedList)3 List (java.util.List)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Component (org.mule.runtime.api.component.Component)3 TypedException (org.mule.runtime.api.exception.TypedException)3 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)3 HashSet (java.util.HashSet)2