execute default fault rule after executing raise fault policy

Hi ,

i defined below fault rule and default fault rule proxy pre flow, i want to call error handler even if raise fault rule is executed

<ProxyEndpoint name="default">
  ........
  <FaultRules>
    <FaultRule name="error-response">
      <Step>
        <Name>RF-JsErrors</Name>
      </Step>
      <Condition>isError = true</Condition>
    </FaultRule>
  </FaultRules>
  
  <DefaultFaultRule name="error-handler">
    <Step>
      <Name>ErrorHandler</Name>
    </Step>
    <AlwaysEnforce>true</AlwaysEnforce>
  </DefaultFaultRule>
  ........


as mentioned in apigee docs:

"However, there's one instance where this isn't the case. If a FaultRule other than the DefaultFaultRule invokes a RaiseFault policy, the DefaultFaultRule does not execute, even if the <AlwaysEnforce> element in the <DefaultFaultRule> tag is true."

so in apigee, DefaultFaultRule will not be executed in case of invoke a RaiseFault policy.

should i replace RF-JsErrors (Raise Fault policy) with assign message policy? or there is a way to enforce executing default fault rule with RaiseFault Policy.

Thanks

Solved Solved
0 1 215
1 ACCEPTED SOLUTION

You should definitely replace it with Assign Message for this use case.

The RaiseFault policy is primarily intended to put the proxy in an error state and abort the current flow. Combined with conditionals this is useful for doing validation of business-logic rules (eg, raise a fault if account.balance < 0). The ability to set the message contents while doing this is useful as a quick-and-dirty alternative to writing a full fault flow just to set an error message but it's not the primary aim of the policy.

Contrary to what you're trying to do here, putting a RaiseFault policy inside a fault rule actually causes the proxy (which is *already* in an error state) to go into a special "double error" state where evaluation of *all* flows is stopped. This can be useful where your fault rule is complex and can legitimately fail (eg, if you tried to fetch a translated error message in the fault rule and the fetch failed) but this doesn't seem to be intentional for you.

Based on what your description it sounds like you want to avoid entering the "double error" state, so Assign Message is what you want here.

View solution in original post

1 REPLY 1

You should definitely replace it with Assign Message for this use case.

The RaiseFault policy is primarily intended to put the proxy in an error state and abort the current flow. Combined with conditionals this is useful for doing validation of business-logic rules (eg, raise a fault if account.balance < 0). The ability to set the message contents while doing this is useful as a quick-and-dirty alternative to writing a full fault flow just to set an error message but it's not the primary aim of the policy.

Contrary to what you're trying to do here, putting a RaiseFault policy inside a fault rule actually causes the proxy (which is *already* in an error state) to go into a special "double error" state where evaluation of *all* flows is stopped. This can be useful where your fault rule is complex and can legitimately fail (eg, if you tried to fetch a translated error message in the fault rule and the fetch failed) but this doesn't seem to be intentional for you.

Based on what your description it sounds like you want to avoid entering the "double error" state, so Assign Message is what you want here.