DefaultFaultRule is not working as expected when Javascript error is happening.

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

Solved Solved
0 2 244
1 ACCEPTED SOLUTION

This is working as expected. Your faultRule1 is actually executed because there's no conditions against it. Rather you have conditions against the individual steps inside of the block ie to conditionally trigger the policies

Either you should set conditions against your fault rules (condition outside of step)

<FaultRulename="faultRule1">
  <Step>
    <Name>RF-ValidateEmail</Name>
  </Step>
  <Step>
    <Name>RF-InvalidToken</Name>
    <Condition>(oauthV2.OA-VerifyToken.failed = true)</Condition>
  </Step>
  <Condition>triggerError==true</Condition>
</FaultRule>

Or set <AlwaysEnforce>true</AlwaysEnforce> in your default fault rule. This will force the default fault rule to trigger even if a fault rule triggered.

View solution in original post

2 REPLIES 2

This is working as expected. Your faultRule1 is actually executed because there's no conditions against it. Rather you have conditions against the individual steps inside of the block ie to conditionally trigger the policies

Either you should set conditions against your fault rules (condition outside of step)

<FaultRulename="faultRule1">
  <Step>
    <Name>RF-ValidateEmail</Name>
  </Step>
  <Step>
    <Name>RF-InvalidToken</Name>
    <Condition>(oauthV2.OA-VerifyToken.failed = true)</Condition>
  </Step>
  <Condition>triggerError==true</Condition>
</FaultRule>

Or set <AlwaysEnforce>true</AlwaysEnforce> in your default fault rule. This will force the default fault rule to trigger even if a fault rule triggered.

Thank you. I missed the AlwaysEnforce true