I’m not sure how to use the DefaultFaultRule block. What we are trying to do is just return a 500 custom JSON message when there is an error that isn’t handled.
According to the documentation:
“You should also add a <DefaultFaultRule> to provide a custom general error message if none of your FaultRules is executed.”
Here is my Fault Rules blocks
<FaultRules>
<FaultRule name="faultRule1">
<Step>
<Condition>triggerError==true</Condition>
<Name>RF-ValidateEmail</Name>
</Step>
<Step>
<Name>RF-InvalidToken</Name>
<Condition>(oauthV2.OA-VerifyToken.failed = true)</Condition>
</Step>
</FaultRule>
</FaultRules>
<DefaultFaultRule name="fault-rule">
<Step>
<Name>RF-ServerError</Name>
</Step>
</DefaultFaultRule>
Here is the RF that is attached to the DefaultFaultRule
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<RaiseFault async="false" continueOnError="false" enabled="true" name="RF-ServerError">
<DisplayName>RF-ServerError</DisplayName>
<Properties/>
<FaultResponse>
<Set>
<Headers/>
<Payload contentType="application/json">
{
"code": 50001,
"message": "Internal Server Error."
}
</Payload>
<StatusCode>500</StatusCode>
<ReasonPhrase>Not Found</ReasonPhrase>
</Set>
</FaultResponse>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</RaiseFault>
Also in one of my Javascript files, I’m purposely putting a code that crashes
r = t //t doesn't exist
So instead of getting
{
"code": 50001,
"message": "Internal Server Error."
}
I am getting this
{
"fault": {
"faultstring": "Execution of JS-ValidateEmail failed with error: Javascript runtime error: \"ReferenceError: \"t\" is not defined. (ValidateEmail.js:10)\"",
"detail": {
"errorcode": "steps.javascript.ScriptExecutionFailed"
}
}
}
It’s rather difficult to put all condition such as fault.name = ScriptExecutionFailed because any unexpected error besides this one might come up.
Please assist