Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Fault handling - Add a default fault always raised on top of other faults

Not applicable

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:

  • Default fault:
<?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>
  • Specific fault (404 here):
<?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:

2910-2016-06-14-16h10-54.png

What I try to avoid is to copy the common fault behavior in all faults:

  • Not wanted Specific fault (404 here):
<?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>
  • Wanted behavior (something like that), in Endpoint:
<?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

0 2 1,041
2 REPLIES 2
Top Solution Authors