Hello,
I would like to raise a default fault every time a fault is raised on top of all fault. The goal is to not copy in all faults the common part. Here is an example:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <RaiseFault async="false" continueOnError="false" enabled="true" name="default-backend-fault"> <DisplayName>Default backend fault</DisplayName> <Properties/> <FaultResponse> <Add> <Headers> <Header name="Ama-Gateway-Request-Id">{messageid}</Header> </Headers> </Add> <Set> <Headers> <Header name="Server">"Amadeus"</Header> </Headers> </Set> </FaultResponse> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> </RaiseFault>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <RaiseFault async="false" continueOnError="false" enabled="true" name="not-found-fault"> <DisplayName>Not Found fault (404)</DisplayName> <FaultResponse> <Set> <Payload contentType="application/json">\{ "status": 404, "message": "Not found. The URI is not valid", "more_info": "For full documentation on the available endpoints, see our API catalog at https://developers.amadeus.com" } </Payload> <StatusCode>404</StatusCode> <ReasonPhrase>Not Found</ReasonPhrase> </Set> </FaultResponse> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> </RaiseFault>
I have checked DefaultFaultRule but it is not raised when another fault is raised:
What I try to avoid is to copy the common fault behavior in all faults:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <RaiseFault async="false" continueOnError="false" enabled="true" name="not-found-fault"> <DisplayName>Not Found fault (404)</DisplayName> <FaultResponse> <!-- Common elements --> <Add> <Headers> <Header name="Ama-Gateway-Request-Id">{messageid}</Header> </Headers> </Add> <Set> <Headers> <Header name="Server">"Amadeus"</Header> </Headers> <!-- END: Common elements --> <Payload contentType="application/json">\{ "status": 404, "message": "Not found. The URI is not valid", "more_info": "For full documentation on the available endpoints, see our API catalog at https://developers.amadeus.com" } </Payload> <StatusCode>404</StatusCode> <ReasonPhrase>Not Found</ReasonPhrase> </Set> </FaultResponse> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> </RaiseFault>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <TargetEndpoint name="default"> <Description/> <FaultRules> <FaultRule name="not-found-error"> <Condition>(response.status.code = 404)</Condition> <Step> <Name>not-found-fault</Name> </Step> <Step> <Name>default-backend-fault</Name> </Step> </FaultRule> </FaultRules> <DefaultFaultRule name="default"> <Step> <Name>default-backend-fault</Name> </Step> <AlwaysEnforce>false</AlwaysEnforce> </DefaultFaultRule> ... </TargetEndpoint
BTW, I have tried this and I was enable to make it work.
Is there a way to implement it or do I need to describe common fault behavior in every specific fault?
Thanks,
Jerome
Hi @jerome.folli,
The problem is in your steps for Wanter behhaviour, both the policies are raise faults. Once your error condition for fault rule not-found-error is satisified, the first step not-found-fault which is raise fault is executed. But it stops there without going to second step as first step is raise fault. So for setting and adding the headers you can use the assign message policy and second step can be used to raise the actual fault you can use assign message or raise fault policy. Hope this helps.
Thanks,
Veera
Hi @jerome.folli,
Take a look at this An error handling pattern for apigee proxies
I think using this pattern would help - it looks similar to your proposed solution.
With this pattern the specific fault details are set as variables in an assign message policy in the FaultRule.
The common parts are in the RaiseFault.Json policy in the pattern above.
RaiseFault.Json is a step in the DefaultFaultRule and setting the DefaultFaultRule's AlwaysEnforce to true means it would always be executed so you can set common attributes for every fault.