FaultRule for ServiceCallout 400 response code

I am trying to capture a ServiceCallout's 400 response in a FaultRule, but it is not working for some reason. The error being returned is:

{
  "fault": {
    "faultstring": "Execution of ServiceCallout authenticate-user failed. Reason: ResponseCode 401 is treated as error",
    "detail": {
      "errorcode": "steps.servicecallout.ExecutionFailed"
    }
  }
}

and the FaultRule I have specified is as follows:

        <FaultRule name="ServiceCalloutErrorResponseCode">
            <Step>
                <Name>do-something</Name>
            </Step>
            <Condition>(fault.name = "ErrorResponseCode")</Condition>
        </FaultRule>

However, the fault rule is not hitting. When I trace, it shows that this condition is false. What condition should I use to capture this type of error?

Solved Solved
0 4 1,493
1 ACCEPTED SOLUTION

HI @Anthony Coelho

The fault name is different and does not match your condition.

You can refer to this link for error codes for Service callouts. You can add more faults to your condition if you want to generalize all these together

<Condition>(fault.name = "ErrorResponseCode") or (fault.name = "ExecutionFailed")</Condition>

Please click "accept" if you accept the answer.

View solution in original post

4 REPLIES 4

HI @Anthony Coelho

The fault name is different and does not match your condition.

You can refer to this link for error codes for Service callouts. You can add more faults to your condition if you want to generalize all these together

<Condition>(fault.name = "ErrorResponseCode") or (fault.name = "ExecutionFailed")</Condition>

Please click "accept" if you accept the answer.

Hi @Sai Saran Vaidyanathan, not sure what you mean by "fault name is different and does not match your condition"? The Condition you specified is the same as the one I used except you added an additional or condition. Can you please expand on your answer?

Looks like the exception/fault that occurred is of type "ExecutionFailed" or in other words not ErrorResponseCode which you are checking in your condition.

The link I provided has all the error codes for Service Callouts.

Hope this helps.

You could also explicitly check for failure on the policy using:

<Condition>servicecallout.YOUR_POLICY_NAME.failed = true</Condition>

The docs are a bit ambiguous on ErrorResponseCode at the link shared.

I've not seen a Service Callout return ErrorResponseCode, that's set when the target backend returns 4xx or 5xx.