1

I'm new to Mule and still trying to wrap my head around Errors and Error Handling.

I would like my sub-flow to "throw" a custom error with additional data. The Raise error connector only supports Type and Description (Where description is a static string).

I have noticed that some connectors errors contain an additional attribute errorMessage which they use to add additional information.

My questions are:

  1. Is it possible to add additional data to Raise error connector generated error?
  2. How do I generate an error with errorMessage attribute?
  3. Is there a "correct" way to Raise and handle errors that I'm missing.

Thanks.

Daniel
  • 2,288
  • 1
  • 14
  • 22
  • Please do not make multiple questions in a question to avoid it to be closed as "Needs more focus" https://stackoverflow.com/help/closed-questions – aled Mar 05 '23 at 12:49

2 Answers2

0

Do not confuse Mule error handling with exceptions in a programming language like Java. Mule errors are intentionally not exceptions, though they may look similar.

errorMessage does not contain custom information. The documentation says it can optionally contain a Mule Message related to the error. It is not a text description of the error or an object that can be customized.

aled
  • 21,330
  • 3
  • 27
  • 34
  • do you have any suggestion for passing additional data to upper flows? Currently i'm using `set-variable` but its fells hacky – Daniel Mar 06 '23 at 09:52
  • It is somewhat Jacky. What kind of data exactly you need to pass? Provide more details of the use case. – aled Mar 06 '23 at 09:58
  • Let say a validation error details. In my case I'm validation a costume formatted file and would like to add the line and data about the error. – Daniel Mar 06 '23 at 10:59
  • You can use the Raise component and set the description to whatever you want: https://docs.mulesoft.com/mule-runtime/4.4/raise-error-component-reference. – aled Mar 06 '23 at 11:18
  • I need it to be **dynamic** and I would like the error details to be more then a simple string (an **object**) – Daniel Mar 06 '23 at 11:43
0

You can transmit error state by using variables before you raise your error. Here is an example:

<flow name="errorFlow1" doc:id="f3ad650b-8202-49aa-a344-c761d8080345" >
    <scheduler doc:name="Scheduler" doc:id="e42b5c55-270b-4166-8e12-f32c7fb5039c" >
        <scheduling-strategy >
            <fixed-frequency frequency="1" timeUnit="DAYS"/>
        </scheduling-strategy>
    </scheduler>
    <flow-ref doc:name="errorFlow2" doc:id="76ab3920-5c95-4dfa-9b88-68d4860e271f" name="errorFlow2"/>
    <error-handler >
        <on-error-continue enableNotifications="true" logException="false" doc:name="On Error Continue" doc:id="50da9879-dbf3-4b8b-9d1d-38aeba868624">
            <logger level="INFO" doc:name="Logger" doc:id="0555bd0e-16cd-4248-94c0-2335957b954e" message="error info: #[vars.extraErrorInfo]" />
        </on-error-continue>
    </error-handler>
</flow>
<flow name="errorFlow2" doc:id="506512be-6591-4566-9adc-3d5ef5273ea3" >
    <set-variable value="Never gonna give you up, never gonna let you down" doc:name="extraErrorInfo" doc:id="361275c6-3f6d-4326-a98e-ae90dfcd61f3" variableName="extraErrorInfo"/>
    <raise-error doc:name="ERROR1" doc:id="bcf7d1ef-17a5-4b45-bcce-5edf3627a49f" description="error 1 occurred" type="APP:ERROR1"/>
</flow>
Ryan Hoegg
  • 2,415
  • 2
  • 14
  • 15