Reputation: 421
This question is a followup to an earlier question here
So: Am trying to read a file from a SFTP location . Am using Mule 4.4 Community edition. If there is any error while connecting to SFTP server or file is not present , would like mule to retry 2 times .
Based on answer from @aled I am now using 'until successful'
Here is the code :
<sftp:config name="SFTP_Config" doc:name="SFTP Config">
<sftp:connection host="abcd" username="xyz" password="pwd" />
</sftp:config>
<flow name="get:employee">
<logger level="INFO" doc:name="Logger" message="starting search" category="get-employee"/>
<until-successful maxRetries="1" doc:name="Until Successful" millisBetweenRetries="30000">
<sftp:read doc:name="Read" config-ref="SFTP_Config" path="/a/employees.unl">
<repeatable-in-memory-stream />
<reconnect />
</sftp:read>
</until-successful>
<error-handler ></error-handler>
</flow>
Now the code is retrying to read file from sftp 1 time at an interval of 30 seconds . All good till here
The bit that has got me confused is - error handling . In my case I am testing without the file being present in sftp so I get the error :
SFTP:ILLEGAL_PATH
However after max retries the error type is :
SFTP:RETRY_EXHAUSTED
IN error handler when I give the type of error to catch as : SFTP:RETRY_EXHAUSTED it is not getting caught !
<on-error-continue enableNotifications="false" logException="false" doc:name="On Error Continue" type="SFTP:RETRY_EXHAUSTED">
</on-error-continue>
when I give the catch block to catch both error types: SFTP:RETRY_EXHAUSTED and SFTP:ILLEGAL_PATH
<on-error-continue enableNotifications="false" logException="false" doc:name="On Error Continue" type=" SFTP:RETRY_EXHAUSTED,SFTP:ILLEGAL_PATH">
</on-error-continue>
The exception is caught but with a warning in log:
Expected error type from flow 'get:employee/errorHandler/2' has matched the following underlying error: ILLEGAL_PATH. Consider changing it to match the reported error: RETRY_EXHAUSTED.
I am unable to understand this behaviour and what is the best way to do error handling ?
Upvotes: 0
Views: 817
Reputation: 3315
It is not SFTP:RETRY_EXHAUSTED
it is MULE:RETRY_EXHAUSTED
. Try to catch MULE:RETRY_EXHAUSTED
or simply RETRY_EXHAUSTED
in the error handler.
You can refer to until-success documentation for more details.
The RETRY_EXHAUSTED
error only wraps the latest error that failed the until-success
scope, which is, in most cases, the one that you would want to know. You can get this error using error.suppressedErrors[0]
.
For example:
If you want to do handle errors differently based on the latest error you can add a condition in the when expression of the error handler. Something like error.suppressedErrors[0].errorType == SOME_ERROR_TYPE
Upvotes: 1