Would like to fire message logging when a fault occurs

scase
Participant III

We have APIs which have customer fault policies to fire if there's a key validation failure, custom errors thrown from javascript, etc but we would like to have a message logging policy fire as well, Of course, once a custom policy fires, a default rule won't fire, even with "AlwaysEnforce".

Are there any ways to get around this without completely tearing apart our proxy flow and moving the RaiseFault policies out of the fault rules and into the proxy/target flows?

0 8 636
8 REPLIES 8

Not applicable

Hi @Sean Case . It's good to see you posting on the community!

Did you try leveraging PostClientFlow? http://apigee.com/docs/api-services/reference/api-proxy-configuration-reference#flows

Let us know post your findings. Cheers!

@Diego Zuluaga will a post client flow be reached if a fault is raised? Ive asked about this before and am not clear that it will once a fault policy is called.

Just to verify, I tried putting the message logging policy in the post flow and it was skipped when the fault rule fired.

Maybe I'm missing something from your scenario, but I've just tried a simple example and AlwaysEnforce seems to work fine regardless another FaultRule was executed. Take a look at the snapshot below.

Attached API Proxy bundle in case you want to execute it.

1016-faultrules.jpg

stupid question - how do i download the package?

Not applicable

Here it is.

scase
Participant III
The example you give is a bit different from what we have. We have fault rules which have a condition upon them which ends up getting met, then fire a raisefault policy, and so the default fault rule doesn't get called. Per the Apigee documentation (http://apigee.com/docs/api-services/content/fault-... If a fault rule other than the default fault rule invokes a Raise Fault policy, the default fault rule does not execute, even if the <AlwaysEnforce> element in the <DefaultFaultRule> tag is true. I think what we might need to do is attach the message logging policy to each and every one of the fault rules as the first item (before the raisefault policies and without a condition) so that it fires before getting to the specified raisefault policy. I'm attaching an edited version of your proxy which is similar to our situation (except our API has most of the fault rules being fired within the proxy request flows). Thanks, Diego!

I see what you mean @Sean Case. Thanks for clarifying the scenario and including the code. I was able to replicate your scenario on my org. The reason this is happening is because raising a FaultRule within the Error flow causes to exit the Error flow as well. For this reason, I typically don't recommend using FaultRules within the Error Flow. In my experience, they're meant to be used within the current flow only and then the Error Flow handles them by other Policies, such as AssignMessage, which can set the same properties to the request object as FaultRules. In this way, the DefaultFaultRule always executes. Hopefully, this is not a major change in your code.