Getting Error while configuring Fault Rule

Not applicable

Hello All,

I am new to APIGEE and upto now I have created a sample API proxy for yahoo weather api which is described in apigee docs page and now i am configuring custom exception handling for the service.

Below is the xml code

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<ProxyEndpoint name="default">

<Description/>

<PreFlow name="PreFlow">

<Request>

<Step>

<FaultRules>

<FaultRule>

<!-- The name of the policy that will execute if the Condition evaluates to true. -->

<Name>fault_SpikeArrestViolation</Name>

<Condition>fault.name = "SpikeArrestViolation"</Condition>

</FaultRule>

<RaiseFault name="fault_SpikeArrestViolation">

<FaultResponse>

<Set>

<Payload contentType="text/plain"> Contact support at support@miraclesoft.com. </Payload>

<StatusCode>429</StatusCode>

<ReasonPhrase>Too Many Requests</ReasonPhrase>

</Set>

</FaultResponse>

<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>

</RaiseFault>

</FaultRules>

<Name>Spike-Arrest-1</Name>

</Step>

</Request>

<Response/>

</PreFlow>

<Flows>

<Flow name="forecast">

<Description/>

<Request/>

<Response/>

<Condition>(proxy.pathsuffix MatchesPath "/forecastrss") and (request.verb = "GET")

</Condition>

</Flow>

</Flows>

<PostFlow name="PostFlow">

<Request/>

<Response>

<Step>

<FaultRules/>

<Name>XML-to-JSON-1</Name>

</Step>

</Response>

</PostFlow>

<HTTPProxyConnection>

<BasePath>/v1/weather</BasePath>

<VirtualHost>default</VirtualHost>

<VirtualHost>secure</VirtualHost>

</HTTPProxyConnection>

<RouteRule name="default">

<TargetEndpoint>default</TargetEndpoint>

</RouteRule>

</ProxyEndpoint>

While configuring the exception handling,I am recieving the following error

Server Error. Error occurred while validation of bean default.xml. Reason: - Schema validation failed. Cause : unexpected element (uri:"", local:"Name"). Expected elements are <{}Condition>,<{}Step>,<{}Description>,<{}Policy>. Line number : 10. Column number : 31. File name : default.xml..

I am not able to know how to correct the xml file specific to the error.I request you to help me in this regard.

Thanks In Advance

0 5 1,274
5 REPLIES 5

Hi @Bharadwaj Kalluri,

Couple of problems,

1. RaiseFault should be a policy in its own xml File, not inline in your proxyEndpoint xml

2. You cannot have FaultRules defined within the Step, it should be done at the top level

You can refer more on FaultHandling here,

http://apigee.com/docs/api-services/content/fault-handling

Tip

If you use UI in 'edge.apigee.com' to create the Proxy, it will be much easier and you will not run into such syntax issues

Try DefaultFaultRule first, that will give you a good idea of how fault handling works, then you can start building more complex fault rules

Thanks,

Mukundha

Please refer to http://apigee.com/docs/api-services/content/fault-handling

to verify your XML is formatted properly.

@Floyd Jones & @Mukundha Madhavan - documentation indicates that FaultRules may be attached to a Step. Can you verify documentation is consistent with this?

Hey @Dallen - Do you have a link to the docs so I can correct it? Thanks!

Something like this would work:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="default">
    <Description>Check for >= 400s</Description>
    <FaultRules>
        <FaultRule name="CheckResponseJS_rule">
            <Step>
                <Name>CheckResponseJS</Name>
            </Step>
            <Condition>(response.status.code = 404)</Condition>
        </FaultRule>
    </FaultRules>
    <HTTPTargetConnection>
        <URL>https://www.example.com/US/en_US/a</URL>
    </HTTPTargetConnection>
    <PreFlow name="PreFlow">
        <Request/>
        <Response/>
    </PreFlow>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
</TargetEndpoint>