Mule private flows and separation of concerns - exception

I have a requirement which I want to solve using Mule. My flow design follows like:
A main-flow with request-response HTTP inbound endpoint. After applying couple of transformations on the current payload this main flow invokes two private flows namely private-flow1 and private-flow2, which are mule private flows whose processing strategy is synchronous.
The private-flow1 invokes an external service using request-response HTTP outbound endpoint.
The private-flow2 places the response from the external service on Database using Database Connector.
If there is any exception in each of the private flows, I want to handle them in the corresponding private flow itself using Catch Exception Strategy.
I have this design to separate the concerns, so that each flow performs a single responsibility.
Suppose there is an exception like IOException, SQLException or any, in any one of the private flows, how can I re-throw my custom exception, for example, org.mycompany.CustomException including the underlying cause. So main-flow will have to handle only org.mycompany.CustomException and build the related exception response.
Say for example, if private-flow1 throws org.mycompany.CustomException which is caused by IOException, the realted exception response would be:
{"exceptionMessage" : External Service unavailable, "exceptionCode" : 101}
and, if private-flow2 throws org.mycompany.CustomException which is caused by SQLException, the realted exception response would be
{"exceptionMessage" : Database unavailable, "exceptionCode" : 102}

Each private flow will have their own exception strategy and you can throw an exception using Groovy component from the flows ..
Here is a link how to do it :- How do I force an exception in mule
for custom exception create java-class which would extend DefaultMessagingExceptionStrategy
Update:-
An example to use custom-exception-strategy:- Why is Mule exception strategy so chatty?

Related

Can Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPage be extended?

In .NET Core you can easily add a detailed exception page for developers:
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
This then gives you the exception details:
However, I'd like to include additional exception detail - for instance the SQL query attempted when the exception is a SqlException.
I can write my own exception handler from scratch with app.UseExceptionHandler, but I'd rather extend the built-in error. For instance by adding a tab to the results including additional info.
Is it possible to extend the information on this exception page?

Spring Integration Exception Handling

What is the concept behind exception handling in Spring Integration or any other EAI framework: Are they treated as a Message?
Lets say that a JMS timeout exception was thrown from jms-outbound-gateway. Now it has to be moved all the way upto the parent custom gateway addEmployeeGateway which defines a method called addEmployee which throws a custom exception called SystemDownException. These two components are connected through request and reply channels and thats the only medium of communication. Does it mean that Exceptions are also treated as messages?
Also, if i had to map the JMS timeout exception to my custom exception SystemDownException and rethrow the SystemDownException how and where would i achieve this. I dont want to use an errorchannel.
The general mechanism for handling exceptions is an error-channel on the inbound (or some intermediate) endpoint; the ErrorMessage payload has failedMessage and cause properties.
The mechanism is similar to try {...} catch {...} in Java.
I dont want to use an errorchannel.
Alternatively, you can configure a custom request handler advice on the JMS outbound gateway; there, you can do whatever you want, including throwing your SystemDownException after catching an exception on callback.execute().

Breeze EF6 SaveChanges doesn't propagate exceptions

In the EFContextProvider (EF6) SaveChangesCore method, the exception handling looks like this:
} catch (Exception e) {
while (e.InnerException != null) {
e = e.InnerException;
}
throw e;
}
This throws only the most internal exception and hides the relevant information revealed by the external exceptions.
When the SaveChanges process goes through multiple layers the next direct layer exception is lost, and only the last exception in the chain is thrown. It doesn't allow to handle well the exceptions for the caller.
Updated Post
As of Breeze 1.4.6, any .NET Exceptions thrown on the server are now available in their original form in the httpResponse.data property of any async breeze result. Breeze will still drill down to extract a "good" error message, but will no longer obscure the initial exception.
Original Post Below -------------------
It's an interesting point. The reason we did this was because most client side apps aren't written to navigate thru the exception chain and we wanted to expose the most 'relevant' error to the client. Most of the apps we looked at just exposed the client "error.message" property directly and with EF errors this was almost always useless.
However, your point is well taken. I think what we need to do is create a new Exception that has a top level message that is the innermost exception message but still expose the entire exception chain for those that want to drill. I've added an internal feature request for this and will try to get it into a near term release ( probably not the next one because we are already in testing for that one).
And thanks for the input.

Enterprise library exception handling problems with WCF services

my application consists of 3 layers and is very straightforward.
class library with all the business logic
WCF service that exposes the class library
asp.net web UI.
At the class library layer, I have an enterprise library exception handling policy defined so that it logs all exceptions to the database. In the underlying code, exceptions are thrown, and they coalesce up to the facade. In the facade, I trigger the EL policy to log the errors, and then I toggle a sucessStatus boolean in the response and have a method to convert all my exceptions to a friendly list so that the ultimate consumer can dig through this to get any idea of whats going on.
My facade in my class library sort of looks like this:
public SomeResponse DoSomething(SomeRequest request)
{
SomeResponse response = new SomeResponse();
try
{
response.data = SomeOperationThatWillThrowAnException;
}
catch (InvalidOperationException ex)
{
var exceptionManager = EnterpriseLibraryContainer.Current.GetInstance<ExceptionManager>();
exceptionManager.HandleException(ex, "StandardPolicy");
response.Errors.Add(Utility.ExceptionToError(ex));
response.SuccessStatus = false;
}
return response;
}
If I build a simple winform client and have it talk to my class library, this works.
However when I use the full stack, I get "fault exception was unhandled by user code". I can't seem to configure EL at the WCF layer in any way to keep this from happening.
My WCF service is just a simple wrapper for my class library facade.
public SomeResponse DoSomething(SomeRequest request)
{
return new MyFacade.DoSomething(request);
}
What I want is to have the class library handle the error silently, and not trigger any exceptions at the WCF or UI level. I want the consumer (in this case the ASP.NET webform UI) to have to check the response message contents to get a clue of what happened instead of having an exception stop execution dead in its tracks.
You likely have an error in your configuration file resulting in GetInstance() or HandleException() throwing an exception. Have you tried debugging the WCF service?

WCF Exception Handling Strategies

We are developing a proxy in WCF that will serve as a means of communication for some handhelds running our custom client application. I am curious what error handling strategies people use as I would rather not wrap EVERY proxy call in try/catch.
When I develop ASP .NET I dont catch the majority of exceptions, I leverage Application_Error in Global asax which can then log the exception, send an email, and redirect the user to a custom error landing page. What I am looking for in WCF is similar to this, except that it would allow me to pass a general faultreason to the client from a central location.
Basically I am curious how people centralize their exception handling in WCF apps.
Thanks
You might find the IErrorHandler interface useful here. We've been using this to do pretty much what you mention - centralised exception logging and providing generalised fault reasons without having to litter the code with numerous try/catches to try and deal with the problem locally.
So here is what I did. We have a few custom exceptions in our application such as BusinessRuleException and ProcessException, WCF supports both FaultException and FaultException<T>.
General practice seems to be that you always throw FaultException to the client in the case of a general error or an error that you dont want to display exactly what happened. In other cases you can pass FaultException<T> where T is a class with information about the particular exception.
I created this concept of Violations in the application, which basically meant that any custom exception had a property containing the corresponding Violation instance. This instance was then passed down to the client enabling the client to recognize when a recoverable error had occured.
This solved part of the problem, but I still wanted a general catch all that would allow me to centeralize logging. I found this by using the IErrorHandle interface and adding my own custom error handler to WCF. Here is the code:
public class ServiceHostGeneralErrorHandler : IErrorHandler
{
public void ProvideFault(Exception ex, MessageVersion version, ref Message fault)
{
if (ex is FaultException)
return;
// a general message to the client
var faultException = new FaultException("A General Error Occured");
MessageFault messageFault = faultException.CreateMessageFault();
fault = Message.CreateMessage(version, messageFault, null);
}
public bool HandleError(Exception ex)
{
// log the exception
// mark as handled
return true;
}
}
Using this method, I can convert the exception from whatever it is to something that can be easily displayed on the client while at the same time logging the real exception for the IT staff to see. So far this approach is working quite well and follows the same structure as other modules in the application.
We use the Exception Handling Application block and shield most faults from clients to avoid disclosing sensitive information, this article might be a good starting point for you, as with "best practices" - you should use what fits your domain.