1
votes

We have a requirement where we want to write a global exception handler so that any exception on any of the individual flows(we have 80+ mule flows) is caught by this global exception handler.

Basically we want to add a global configuration and associate a default global catch exception strategy so that any exception in any of the flows are handled here.

Adding each 'catch exception strategy' per flow works but I have to repeat the similar code 50+ times which I want to avoid for obvious reasons.

Also, please note I want to pass specific parameters to this global exception strategy so that this global exception strategy gives flow specific info as well. Please suggest.

Note: I do not see a global catch exception strategy option in 'Global Elements' of mule UI.

References:

Mule specific docs do not clarify clearly.

https://docs.mulesoft.com/mule-user-guide/v/3.7/error-handling

This requirement looks very similar but not very clear about passing parameters etc:

How to add a global exception handler/logger once in Mule

2
Create global - catch exception strategy or choice Exception Strategy ( where you catch can multiple exceptions) and refer it via reference-exception-strategy in flows. Have you gone through docs.mulesoft.com/mule-user-guide/v/3.7/…?. - star
Thanks a lot for your comment. Yes, I have seen it. In this link, it says: "If you have not already done so, create a global catch, rollback, or choice exception strategy to which your reference exception strategy can refer." But how do I create it(using xml, as I do not see it in UI) is my challenge and I am not clear. Any help will be appreciated. - learner
So as I see it, there are 2 options: (1) create a global catch exception strategy and have a reference exception strategy in each flow refer to this global policy. (2) Create a global catch exception strategy and have a global configuration refer it. Advantage of option(2) is we do not need to refer each existing flow and future flows to the global catch strategy. However, the first step in either of the above options is to create a global catch strategy, which is not clear from the mule docs(specially when I cannot see 'catch exception strategy' in UI). - learner
In a Mule palette - type 'Catch Exception' it will list for you. Else hover the mouse on 'exclamation symbol - !' which is present on Right side corner of Mule Palette it will list all the Error Handling Component. - star
I can't upload the image via comment section.Hence using Answer. - star

2 Answers

1
votes

enter image description hereYou should able to see it in UI. Not sure why you are not able to. If my understanding is correct. Please find the screenshot.

  <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" basePath="test" doc:name="HTTP Listener Configuration"/>
     <flow name="TestFlow">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
    <logger level="INFO" doc:name="Logger"/>
    <set-payload value="#['Hello World']" doc:name="Set Payload"/>
    <exception-strategy ref="Choice_Exception_Strategy" doc:name="Reference Exception Strategy"/>
</flow>
<choice-exception-strategy name="Choice_Exception_Strategy">
    <catch-exception-strategy when="exception.causeMatches(java.lang.ArithmeticException)" doc:name="Catch Exception Strategy- Arithmetic Exception">
        <logger level="INFO" doc:name="Logger"/>
    </catch-exception-strategy>
    <catch-exception-strategy doc:name="Catch Exception Strategy-All Exception">
        <logger level="INFO" doc:name="Logger"/>
    </catch-exception-strategy>
</choice-exception-strategy>

As per in your comments you can use the whatever feasible methods suits you.

If you are using old version. Palette looks like in the url mentioned here https://docs.mulesoft.com/mule-user-guide/v/3.7/catch-exception-strategy

1
votes

star's suggestion was good. Also, if you want to pass parameters into the global exception handler, a good approach is to set a flow variable that global exception reads and never forget to put a value into this variable on each flow you have.