Reputation: 11456
I have a Mule flow which updates Magento Invtory through SOAP API. Everything runs great until I try to update an item which is not in the Magento Database. I then get an exception.
ERROR 2016-06-17 12:31:06,523 [[bwgs-to-magento].bwgs-to-magentoFlow.stage1.02] org.mule.retry.notifiers.ConnectNotifier: Failed to connect/reconnect: Work Descriptor. Root Exception was: Product not exists.. Type: class org.apache.axis.AxisFault
My exception strategy is this:
<choice-exception-strategy doc:name="Choice Exception Strategy">
<catch-exception-strategy when="#[exception.causedExactlyBy(org.mule.api.MessagingException)]" doc:name="Catch Exception Strategy">
<logger message="error" level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
</choice-exception-strategy>
My desired result is when an exception occurs, log it, but keep processing the flow. Edit: I have also tried the following exception strategy:
<choice-exception-strategy doc:name="Choice Exception Strategy">
<catch-exception-strategy when="#[exception.causeMatches(org.mule.api.*)]" enableNotifications="true" doc:name="Catch Exception Strategy">
<logger message="#[exception.cause.message]" level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
</choice-exception-strategy>
Here is the error syntax:
ERROR 2016-06-20 10:47:03,080 [[bwgs-to-magento].bwgs-to-magentoFlow.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy:
Message : Failed to invoke updateInventoryStockItem. Message payload is of type: String[] Type : org.mule.api.MessagingException Code : MULE_ERROR--2 Payload : [Ljava.lang.String;@191acd5 JavaDoc : http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html
Exception stack is: 1. Product not exists. (org.apache.axis.AxisFault) org.apache.axis.message.SOAPFaultBuilder:222 (null) 2. Product not exists. (org.mule.module.magento.api.MagentoException) org.mule.module.magento.api.MagentoClientAdaptor:83 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/module/magento/api/MagentoException.html) 3. Failed to invoke updateInventoryStockItem. Message payload is of type: String[] (org.mule.api.MessagingException) org.mule.devkit.processor.DevkitBasedMessageProcessor:133 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
Upvotes: 0
Views: 131
Reputation: 1503
In the MagnetoFlow make the flow end at DB level with flowRef
and rest of the logic will continue in the next flow.If suppose exception happens it will caught in exception strategy. Here you log the exception and keep continue with the flow Ref of pendingLogic_MagnetoFlow
. Check in choice whether the payload is available to continue( because here flow if flow continue from exception payload mightn't present), if so use the sessionVars where you have stored in session variable to continue with other logics.
<flow name="magnetoFlow">
<set-session-variable variableName="originalPayload" value="#[payload]" doc:name="Session Variable"/>
---DB here----
<flow-ref name="pendingLogicFrom_MagnetoFlow" doc:name="Flow Reference"/>
<catch-exception-strategy doc:name="Catch Exception Strategy" when="#[exception.causeMatches(org.mule.api.*)]">
<logger message="#[exception.cause.message]" level="INFO" doc:name="Logger"/>
<flow-ref name="pendingLogicFrom_MagnetoFlow" doc:name="pendingLogicFrom_MagnetoFlow"/>
</catch-exception-strategy>
</flow>
<flow name="pendingLogicFrom_MagnetoFlow">
<choice doc:name="Choice">
<when expression="#[check the payload is empty or not here ]">
<set-payload value="#[seesionVars.originalPayload]" doc:name="Set Payload"/>
</when>
<otherwise>
<logger level="INFO" doc:name="Logger"/>
</otherwise>
</choice>
<logger level="INFO" doc:name="Logger"/>
---other normal logic here ---
</flow>
Check this out.
Upvotes: -1
Reputation: 11606
The best way to handle this scenario is your flow design. Put the Magento operation and the exception strategy in their own private flow and reference it from another flow. This way the exception will be caught and handled in the private flow and processing will return to the main flow where you can continue doing anything you want. For example:
<flow name="main-flow">
<flow-ref name="magento-flow" />
<logger level="INFO" message="This will continue processing" />
</flow>
<flow name="magento-flow">
<magento ... />
<choice-exception-strategy doc:name="Choice Exception Strategy">
<catch-exception-strategy when="#[exception.causeMatches(org.mule.api.*)]" enableNotifications="true" doc:name="Catch Exception Strategy">
<logger message="#[exception.cause.message]" level="INFO" doc:name="Logger"/>
</catch-exception-strategy>
</choice-exception-strategy>
</flow>
Upvotes: 2