Project: mule
Issue MULE-8908: Add the concept of ExceptionEnricher in Ext-Api
Add the concept of an ExceptionEnricher in the ext-api which gets invoked whenever an operation throws an exception. This is useful to avoid repetitive try..catch blocks. It would be defined by an interface roughly looking like this {code:java} public interface ExceptionEnricher { Exception enrichException(Exception e); } {code} Then you can declare it at an Extension level: {code:java} @Extension @Operations(Operations.class); @OnException(handler = PetExceptionEnricher.class) public class PetStoreConnector { … } {code} Or at a configuration level: {code:java} @Configuration(name="pooled-config") @PooledConnector(PetClientConnectionHandler.class) @OnException(handler = PooledPetConnectionExceptionEnricher.class) public class PooledConnectionConfig { } {code} A simple implementation would look similar to this: {code:java} public class PetExceptionEnricher implements ExceptionEnricher {	public Exception enrichException(Exception e) {	if (irrelevantException(e)) {	logger.error(e.getMessage())	} else if (e instanceof SocketException) {	return new ConnectionException(e); // wants to reconnect	} else {	return e; } } } {code}
Story points: 8