learner
learner

Reputation: 94

global exception handler - mule

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

Upvotes: 1

Views: 1471

Answers (2)

Star
Star

Reputation: 1503

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

Upvotes: 1

pao
pao

Reputation: 11

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.

Upvotes: 1

Related Questions