Search in sources :

Example 1 with ErrorTypeProvider

use of org.mule.runtime.extension.api.annotation.error.ErrorTypeProvider in project mule by mulesoft.

the class ErrorsDeclarationEnricher method registerOperationErrorTypes.

private void registerOperationErrorTypes(MethodElement operationMethod, ComponentDeclaration operation, ErrorsModelFactory errorModelDescriber, ErrorTypeDefinition<?>[] extensionErrorTypes, Type extensionElement) {
    if (extensionElement.getDeclaringClass().isPresent()) {
        getOperationThrowsDeclaration(operationMethod, extensionElement).ifPresent(throwsAnnotation -> {
            Class<? extends ErrorTypeProvider>[] providers = throwsAnnotation.value();
            Stream.of(providers).forEach(provider -> {
                try {
                    ErrorTypeProvider errorTypeProvider = provider.newInstance();
                    errorTypeProvider.getErrorTypes().stream().map(error -> validateOperationThrows(extensionErrorTypes, error)).map(errorModelDescriber::getErrorModel).forEach(operation::addErrorModel);
                } catch (InstantiationException | IllegalAccessException e) {
                    throw new MuleRuntimeException(createStaticMessage("Could not create ErrorTypeProvider of type " + provider.getName()), e);
                }
            });
        });
    }
}
Also used : MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ErrorTypeProvider(org.mule.runtime.extension.api.annotation.error.ErrorTypeProvider)

Aggregations

MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 ErrorTypeProvider (org.mule.runtime.extension.api.annotation.error.ErrorTypeProvider)1