Will 2nd step in default fault rule executes if there occurs an error in 1st step ?

Hi Experts,

If I have default fault rule like below, with 3 steps and 1 policy in each step.

<DefaultFaultRule name="default-rule">
    <AlwaysEnforce>true</AlwaysEnforce>
    <Step>
         <Name>JavaScriptCatchJSErrors</Name>
    </Step>
    <Step>
        <Name>AssignMessageGenerateFaultResponse</Name>
    </Step>
    <Step>
        <Name>ServiceCalloutLogError</Name>
    </Step>
</DefaultFaultRule>

If the JavaScriptCatchJSErrors policy errors out in runtime, will policy in 2nd step i.e,  AssignMessageGenerateFaultResponse executes or the default fault rule flow terminates ?

Thanks in advance

0 1 77
1 REPLY 1

No, the steps that follow a step that generated a fault, will not execute. 

To demonstrate this, you can try it yourself. Created this DefaultFaultRule:

  <DefaultFaultRule name="default-fault-rule">
    <Step>
      <Name>AM-Inject-Proxy-Revision-Header</Name>
    </Step>
    <Step>
      <Name>AM-Inject-Step1-Header</Name>
    </Step>
    <Step>
      <Name>JS-Fail</Name> <!-- always fail -->
    </Step>
    <Step>
      <Name>AM-Inject-Step2-Header</Name>
    </Step>
    <AlwaysEnforce>true</AlwaysEnforce>
  </DefaultFaultRule>

Each of those AM-* steps simply injects a header into the response. The AM-Inject-Step1-Header policy looks like this:

<AssignMessage name='AM-Inject-Step1-Header'>
  <Set>
    <Headers>
      <Header name='Proxy-Step-1'>true</Header>
    </Headers>
  </Set>
</AssignMessage>

The JS-Fail step looks like this: 

<Javascript name='JS-Fail' timeLimit='200' >
  <Source>
    throw new Error('unknown failure in JS');
  </Source>
</Javascript>

I inserted this DefaultFaultRule into a proxy bundle that connects to expired.badssl.com, an endpoint that always presents an expired certificate. When I send in a request, Apigee experiences a target fault. When control returns to the proxyEndpoint, the DefaultFaultRule gets executed. I can see 

  • the proxy revision header
  • the step1 header
  • no step2 header

Conclusion: The DefaultFaultRule terminates. 

Incidentally, you didn't ask, but I suggest that you do not perform ServiceCallout within DefaultFaultRule.  Instead, do it within the PostClientFlow.  This will minimize latency by the client, and it also protects your proxy from the sort of unpredictable errors that can arise from invoking remote services. Just set variables in the DefaultFaultRule, and then reference those variables in the PostClientFlow.