DefaultFaultRule is executed twice

Hi all,

I defined a DefaultFaultRule (DFR) handler in my TargetEndpoint and ProxyEndpoint.

Both uses the same sharedflow.

If I throw an error (let say a javascript exception in my TargetEndpoint (REQ or RESP)), DFR will be executed twice.

I kept DFR only in my ProxyEndpoint, then when the exception is thrown again in my TargetEndpoint (REQ or RESP), only the DFR of the ProxyEndpoint is executed once.

What's wrong with my design?

Solved Solved
1 6 523
1 ACCEPTED SOLUTION

There's nothing wrong with your design. There may be something wrong with your expectation.

The fault rules run when a fault occurs. As you know, in an API Proxy, you may attach logic to the Proxy Endpoint and the Target Endpoint.

5803-screenshot-20171023-111210.png

It seems that you have configured a fault rule in the target endpoint (the blue boxes in the above diagram), AND you have configured a fault rule in the proxy endpoint (orange-red boxes). From what you wrote, it seems like both fault rules are executing. This is expected behavior.

A fault condition occurs when the target responds with a non-success code. (By default this is any HTTP status code not between 200 and 399, but you can override this with the 'success.codes' property on a TargetEndpoint.) If you want only ONE of those fault rules to execute, then you'll need to be more thoughtful about how you configure your logic.

Some options there:

  • set a variable inside the fault rule on the target endpoint, and then inspect that variable in a Condition that wraps the FaultRule or the Step inside the FaultRule on subsequent invocations within the same request context
  • Do not configure a fault rule on both the targetendpoint and the proxy endpoint. (Are you sure you need both?)

View solution in original post

6 REPLIES 6

There's nothing wrong with your design. There may be something wrong with your expectation.

The fault rules run when a fault occurs. As you know, in an API Proxy, you may attach logic to the Proxy Endpoint and the Target Endpoint.

5803-screenshot-20171023-111210.png

It seems that you have configured a fault rule in the target endpoint (the blue boxes in the above diagram), AND you have configured a fault rule in the proxy endpoint (orange-red boxes). From what you wrote, it seems like both fault rules are executing. This is expected behavior.

A fault condition occurs when the target responds with a non-success code. (By default this is any HTTP status code not between 200 and 399, but you can override this with the 'success.codes' property on a TargetEndpoint.) If you want only ONE of those fault rules to execute, then you'll need to be more thoughtful about how you configure your logic.

Some options there:

  • set a variable inside the fault rule on the target endpoint, and then inspect that variable in a Condition that wraps the FaultRule or the Step inside the FaultRule on subsequent invocations within the same request context
  • Do not configure a fault rule on both the targetendpoint and the proxy endpoint. (Are you sure you need both?)

Hi @Dino,

I haven't configured any FaultRule (FR) in my {Target|Proxy}Endpoints.

The DFR (which is declared in my {Target|Proxy}Endpoints) handle all my logic error (example: custom exception, Apigee exception, etc).

Both of them use the same SharedFlow (SF).

This is my DFR configuration:

  <DefaultFaultRule name="DefaultFaultRule">
        <Step>
            <Condition>x-log.custom_exception != true</Condition>
            <FaultRules/>
            <Name>sf-xxxxx-default-fault-rule-proxy</Name>
        </Step>
        <AlwaysEnforce>true</AlwaysEnforce>
    </DefaultFaultRule>

I want to share my experience.

Let's say:

DFR1: DefaultFaultRule configured in ProxyEndpoint

DFR2: DefaultFaultRule configured in TargetEndpoint

DFR1 && DFR2: DefaultFaultRule configured in ProxyEndpoint && TargetEndpoint

Test number Exception thrown in: DFR1 && DFR2 are configured Only DFR1 is configured Only DFR2 is configured
1 ProxyReqPreFlow DFR1 is executed DFR1 is executed DFR2 is skipped
2 ProxyReqPostFlow DFR1 is executed DFR1 is executed

DFR2 is skipped

3 TargetReqPreFlow DFR1 && DFR2 are executed DFR1 is executed DFR2 is executed
4 TargetReqPostFlow DFR1 && DFR2 are executed DFR1 is executed DFR2 is executed
5 TargetRespPreFlow DFR1 && DFR2 are executed DFR1 is executed DFR2 is executed
6 TargetRespPostFlow DFR1 && DFR2 are executed DFR1 is executed DFR2 is executed
7 ProxyRespPreFlow DFR1 is executed DFR1 is executed

DFR2 is skipped

8 ProxyRespPostFlow DFR1 is executed DFR1 is executed

DFR2 is skipped

I dont understand why DFR is executed in both Endpoint (see test number, 3,4,5 et 6). Is it expected ?

Thank you for your help.

yes, I think it is expected. You have configured a DefaultFaultRule in both Target and Proxy endpoints. They both execute when the error occurs in the target. I think this is expected behavior.

Maybe what I said earlier was not clear. Here's another go: if you wish the sequence of policies to not run the second time, then within the sequence, you can set a variable (AssignMessage), and wrap the sequence with a Condition to check whether the policy has already run.

Or, re-consider how you configure the DefaultFaultRules.

Thank you @Dino, may be I will set a variable to true if DefaultFaultRule is executed in TargetEndpoint side, then the ProxyEndpoint's DefaultFaultRule have to skeep if that variable is true

That sounds like a good plan!

I'm in a similar situation. Is there a reason it was designed this way? Because I can't think of a scenario where one would require both the target and proxy default fault rules executed. @Dino-at-Google, @Anil Sagar

Also it would be helpful if this information is captured in the docs. @Floyd Jones