use of org.mule.runtime.api.meta.model.error.ErrorModel in project mule by mulesoft.
the class ErrorsDeclarationEnricherTestCase method operationsWithConnectionsThrowsConnectivityError.
@Test
public void operationsWithConnectionsThrowsConnectivityError() {
extensionModel = loadExtension(HeisenbergExtension.class);
OperationModel callSaul = getNamedObject(extensionModel.getConfigurationModel("config").get().getOperationModels(), "callSaul");
Set<ErrorModel> errorTypesIdentifiers = callSaul.getErrorModels();
assertThat(errorTypesIdentifiers, hasItem(hasProperty(TYPE, is(CONNECTIVITY_ERROR_IDENTIFIER))));
}
use of org.mule.runtime.api.meta.model.error.ErrorModel in project mule by mulesoft.
the class ErrorsDeclarationEnricherTestCase method orphanErrorsUsesAnyAsParent.
@Test
public void orphanErrorsUsesAnyAsParent() {
extensionModel = loadExtension(HeisenbergWithOrphanErrors.class);
ErrorModel errorModel = extensionModel.getErrorModels().stream().filter(error -> error.getType().equals("HEALTH")).findFirst().get();
assertThat(errorModel.getNamespace(), is(HEISENBERG));
Optional<ErrorModel> anyExtensionError = errorModel.getParent();
assertThat(anyExtensionError.isPresent(), is(true));
assertThat(anyExtensionError.get().getType(), is(ANY.getType()));
assertThat(anyExtensionError.get().getNamespace(), is(MULE_NAMESPACE));
}
use of org.mule.runtime.api.meta.model.error.ErrorModel in project mule by mulesoft.
the class MuleExtensionModelDeclarer method declareErrors.
private void declareErrors(ExtensionDeclarer extensionDeclarer) {
final ErrorModel criticalError = newError(CRITICAL).handleable(false).build();
final ErrorModel overloadError = newError(OVERLOAD).withParent(criticalError).build();
final ErrorModel securityError = newError(SECURITY).withParent(anyError).build();
final ErrorModel sourceError = newError(SOURCE).withParent(anyError).build();
final ErrorModel sourceResponseError = newError(SOURCE_RESPONSE).withParent(anyError).build();
final ErrorModel serverSecurityError = newError(SERVER_SECURITY).withParent(securityError).build();
extensionDeclarer.withErrorModel(anyError);
extensionDeclarer.withErrorModel(newError(EXPRESSION).withParent(anyError).build());
extensionDeclarer.withErrorModel(newError(TRANSFORMATION).withParent(anyError).build());
extensionDeclarer.withErrorModel(newError(CONNECTIVITY).withParent(anyError).build());
extensionDeclarer.withErrorModel(newError(RETRY_EXHAUSTED).withParent(anyError).build());
extensionDeclarer.withErrorModel(newError(REDELIVERY_EXHAUSTED).withParent(anyError).build());
extensionDeclarer.withErrorModel(newError(STREAM_MAXIMUM_SIZE_EXCEEDED).withParent(anyError).build());
extensionDeclarer.withErrorModel(newError(TIMEOUT).withParent(anyError).build());
extensionDeclarer.withErrorModel(newError(UNKNOWN).handleable(false).withParent(anyError).build());
extensionDeclarer.withErrorModel(routingError);
extensionDeclarer.withErrorModel(compositeRoutingError);
extensionDeclarer.withErrorModel(validationError);
extensionDeclarer.withErrorModel(duplicateMessageError);
extensionDeclarer.withErrorModel(securityError);
extensionDeclarer.withErrorModel(serverSecurityError);
extensionDeclarer.withErrorModel(newError(CLIENT_SECURITY).withParent(securityError).build());
extensionDeclarer.withErrorModel(newError(NOT_PERMITTED).withParent(securityError).build());
extensionDeclarer.withErrorModel(sourceError);
extensionDeclarer.withErrorModel(sourceResponseError);
extensionDeclarer.withErrorModel(newError(SOURCE_ERROR_RESPONSE_GENERATE).handleable(false).withParent(sourceError).build());
extensionDeclarer.withErrorModel(newError(SOURCE_ERROR_RESPONSE_SEND).handleable(false).withParent(sourceError).build());
extensionDeclarer.withErrorModel(newError(SOURCE_RESPONSE_GENERATE).withParent(sourceResponseError).build());
extensionDeclarer.withErrorModel(newError(SOURCE_RESPONSE_SEND).handleable(false).withParent(sourceResponseError).build());
extensionDeclarer.withErrorModel(criticalError);
extensionDeclarer.withErrorModel(overloadError);
extensionDeclarer.withErrorModel(newError(FLOW_BACK_PRESSURE).handleable(false).withParent(overloadError).build());
extensionDeclarer.withErrorModel(newError(FATAL).handleable(false).withParent(criticalError).build());
}
use of org.mule.runtime.api.meta.model.error.ErrorModel in project mule by mulesoft.
the class ModuleExceptionHandlerTestCase method handleThrowingChildErrorsFromTheOneDeclared.
@Test
public void handleThrowingChildErrorsFromTheOneDeclared() {
Set<ErrorModel> errors = new HashSet<>();
ErrorModel parent = newError(PARENT.getType(), ERROR_NAMESPACE).build();
ErrorModel child = newError(CHILD.getType(), ERROR_NAMESPACE).withParent(parent).build();
errors.add(parent);
ErrorType parentErrorType = typeRepository.addErrorType(getIdentifier(parent), typeRepository.getAnyErrorType());
typeRepository.addErrorType(getIdentifier(child), parentErrorType);
when(operationModel.getErrorModels()).thenReturn(errors);
ModuleExceptionHandler handler = new ModuleExceptionHandler(operationModel, extensionModel, typeRepository);
ModuleException moduleException = new ModuleException(CHILD, new RuntimeException());
Throwable throwable = handler.processException(moduleException);
assertThat(throwable, is(instanceOf(TypedException.class)));
ErrorType errorType = ((TypedException) throwable).getErrorType();
assertThat(errorType.getIdentifier(), is(CHILD.getType()));
assertThat(errorType.getNamespace(), is(ERROR_NAMESPACE));
}
use of org.mule.runtime.api.meta.model.error.ErrorModel in project mule by mulesoft.
the class ExtensionErrorsRegistrant method registerErrors.
/**
* Registers the found {@link ErrorModel} from each {@link OperationModel} into the {@link ErrorTypeRepository} and creates an
* {@link ExceptionMapper} for each {@link OperationModel} that declares {@link ErrorModel}s.
*
* @param extensionModel from where get the {@link ErrorModel} from each {@link OperationModel}
*/
void registerErrors(ExtensionModel extensionModel) {
Set<ErrorModel> errorTypes = extensionModel.getErrorModels();
String extensionNamespace = extensionModel.getXmlDslModel().getPrefix();
String errorExtensionNamespace = MuleExtensionUtils.getExtensionsNamespace(extensionModel);
DslSyntaxResolver syntaxResolver = DslSyntaxResolver.getDefault(extensionModel, new SingleExtensionImportTypesStrategy());
ErrorModel connectivityErrorModel = newError(CONNECTIVITY_ERROR_IDENTIFIER, errorExtensionNamespace).withParent(newError(CONNECTIVITY_ERROR_IDENTIFIER, MULE).build()).build();
ErrorModel retryExhaustedError = newError(RETRY_EXHAUSTED_ERROR_IDENTIFIER, errorExtensionNamespace).withParent(newError(RETRY_EXHAUSTED_ERROR_IDENTIFIER, MULE).build()).build();
errorTypes.forEach(errorModel -> getErrorType(errorModel, extensionModel));
ExtensionWalker extensionWalker = new IdempotentExtensionWalker() {
@Override
protected void onOperation(OperationModel model) {
registerErrors(model);
}
@Override
protected void onConstruct(ConstructModel model) {
registerErrors(model);
}
private void registerErrors(ComponentModel model) {
if (!errorTypes.isEmpty()) {
ExceptionMapper.Builder builder = ExceptionMapper.builder();
builder.addExceptionMapping(ConnectionException.class, getErrorType(connectivityErrorModel, extensionModel));
builder.addExceptionMapping(RetryPolicyExhaustedException.class, getErrorType(retryExhaustedError, extensionModel));
String elementName = syntaxResolver.resolve(model).getElementName();
errorTypeLocator.addComponentExceptionMapper(createIdentifier(elementName, extensionNamespace), builder.build());
}
}
};
extensionWalker.walk(extensionModel);
}
Aggregations