I want to always execute a policy after every failure in the proxy execution.The result of that policy should be sent to client
So,I tried putting in the Default Fault Rule but when there is failure happening in the <FaultRules>,this is not executed evenif AlwaysEnforce is true.This is expected.
I cannot put this policy in PostClient flow since I want this to be executed before the output goes to client.
Is there anyway to do this?
Solved! Go to Solution.
@RK4 I've used DefaultFaultRule in the Proxy with Always set to true as my last policy to assign a "standard error message" using AssignMessage. I catch the Faults in FaultRules and do an intermediate AssignMessage to set headers which are then used in the final DefaultFaultRule AssignMessage.
Here's a fragment:
<ProxyEndpoint name="default"> <Description/> <DefaultFaultRule name="DefaultFaultRule"> <Step> <FaultRules/> <Name>AM-Default-Proxy-Fault</Name> </Step> <AlwaysEnforce>true</AlwaysEnforce> </DefaultFaultRule> <FaultRules> <FaultRule name="no-apikey"> <Condition>fault.name = "FailedToResolveAPIKey" or fault.name = "InvalidApiKey"</Condition> <Step> <FaultRules/> <Name>Assign-Message-No-Apikey</Name> </Step> </FaultRule> <FaultRule name="raise-fault"> <Condition>fault.name = "RaiseFault"</Condition> <Step> <FaultRules/> <Name>Assign-Message-Raise-Fault-1</Name> </Step> </FaultRule> <FaultRule name="raise-fault"> <Condition>fault.name = "RaiseFault"</Condition> <Step> <FaultRules/> <Name>Assign-Message-Raise-Fault-2</Name> </Step> </FaultRule> </FaultRules>
In the various FaultRule AssignMessage policy, I Add header X-trace to show what policies have been executed.
What I discovered is that the DefaultFaultRule in the Proxy fires all the time, even if the DefaultFaultRule in the Target fires. Also note that I'm catching multiple RaiseFault conditions, but the only one that gets fired is Raise-Fault-2, shows order of execution
This accomplished what I wanted to do, use AssignMessage to standardize all faults.