Question

Suppose I have this target defined:

<TargetEndpoint name="default">
    <PreFlow name="PreFlow">
        <Request/>
        <Response/>
    </PreFlow>
    <HTTPTargetConnection>
        <URL>http://host1.example.com:39282</URL>
    </HTTPTargetConnection>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <FaultRules>
         ....
    </FaultRules>
</TargetEndpoint>

How do I catch target errors like "Connection refused", which would occur when the target is not listening on the given port, or "Host not reachable", which would occur if there is no route to the given host or if the DNS name is not resolvable?

Basically I want the recipe for how to specify the FaultRule that would be placed inside the FaultRules element above.

<FaultRules>
    <FaultRule name="catch1">
        <Condition>WHAT GOES HERE???</Condition>  <!--- ??? --->
        <Step>
            <Name>AssignMessage-1</Name>
        </Step>
    </FaultRule>
    <FaultRule name="catch2">
        <Step>
            <Name>AssignMessage-2</Name>
        </Step>
    </FaultRule>
</FaultRules>

No correct solution

OTHER TIPS

You can use the fault.name variable to check the error (http://apigee.com/docs/api-services/content/policy-attachment-and-enforcement#policy-based-fault-handling)

For example:

<TargetEndpoint name="default">
    <FaultRules>
        <FaultRule name="bad_network">
           <Condition>(fault.name = "ServiceUnavailable")</Condition>
...

The way I got to 'ServiceUnavailable' as the fault name, was by first having the FaultRule policy with no conditions, and then trying a few 'bad target' scenarios - right address/wrong port and wrong address/name both generate the same fault name and can be caught using the above snippet.

To see the error name, you just need to add in an AssignMessage policy a block to read the fault.name variable and in the trace it'll be displayed in the 'Variables Got' session, or assign it to the payload of your response.

Once you have captured all the faults you want to handle, you can go back and modify the proxy faultrules session.

One last note, the FaultRule session above must be in the target endpoint for it to catch the network error on the target side.

Cheers,

Ricardo

yeah!, working, its important where you put the FaultRule: "TargetEndpoint", i was wrong setting in "ProxyEndpoint"

my example:

`<TargetEndpoint name="TargetEndpoint">
<Description/>
<FaultRules>
    <FaultRule name="HTTPError">
        <Step>
            <Name>Raise-Fault-5xx</Name>
            <Condition>message.status.code = 503</Condition>
        </Step>
    </FaultRule>
</FaultRules>
...

`

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top