gtx911
gtx911

Reputation: 1289

Mulesoft - Force exception according to statusCode

I've implemented a Mule flow that reads CSV files and insert the records into Salesforce using a batch.

To manage the errors I have created a step that only accepts failed records.

I've tried modifying the original values so that it fails and proving that it works properly.

The Salesforce response message is a JSON containing a field called statusCode with the following value: INVALID_TYPE_ON_FIELD_IN_RECORD.

However Mule does not recognize it as an error and does not fail so it never enters the Step of failed records.

enter image description here

How can I modify this? Should I change it in Salesforce or add the statusCode cases in Error Mapping?

Upvotes: 0

Views: 333

Answers (1)

Ryan Carter
Ryan Carter

Reputation: 11606

In Mule 4 you can use raiser-error to force an error. Then you just need to define what expression to trigger your expression:

#[sizeOf((payload.errors default [])) > 0]

or

#[payload.errors[0].statusCode=='INVALID_TYPE_ON_FIELD_IN_RECORD']

etc.

Example using choice router:

<choice doc:name="successful?">
            <when expression="#[sizeOf((payload.errors default [])) > 0]">
                <raise-error type="APP:INVALID_TYPE_ON_FIELD_IN_RECORD" />
            </when>
        </choice>

Alternative to controlling flow with errors is setting the acceptExpression on the batch step with the same expression:

<batch:step name="step1" acceptExpression="#[sizeOf((payload.errors default [])) > 0]">

Upvotes: 2

Related Questions