DefaultFaultRule not firing after another fault, even with AlwaysEnforce

Not applicable

I have a `DefaultFaultRule` setup to make an HTTP request in the event of any form of fault in my proxy. It has the `AlwaysEnforce` child element set to "true". However, when a fault is caused (in this case, a quota violation) the default rule never fires. Putting a trace on the API indicates that control switches to the error flow and the correct fault handler is picked up, but then the response is sent straight to the client without considering the default fault rule.

How can I ensure the `DefaultFaultRule` always fires?

0 4 312
4 REPLIES 4

Are you raising another fault from within that fault handler? That would prevent DefaultFaultRule execution.

Not applicable

I believe you are talking about the faultrules in the steps ? that doesn't work .

Former Community Member
Not applicable

HI @Adam Wright, I have included a sample proxy bundle that you can import & test out how the DefaultFaultRule could work. In this proxy I have a simple SpikeArrest policy that is set to a rate of 2pm (i.e. don't allow more than 2 requests / minute). Here is how your proxy configuration should look like:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
    <Description/>
    <PreFlow name="PreFlow">
        <Request>
            <Step>
                <Name>Spike-Arrest-1</Name>
            </Step>
        </Request>
        <Response/>
    </PreFlow>
    <Flows/>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <HTTPProxyConnection>
        <BasePath>/defaultruleproxy</BasePath>
        <VirtualHost>default</VirtualHost>
        <VirtualHost>secure</VirtualHost>
    </HTTPProxyConnection>
    <RouteRule name="noroute"/>
    <DefaultFaultRule name="fault-rule">
        <Step>
            <Name>Assign-Message-1</Name>
        </Step>
    </DefaultFaultRule>
</ProxyEndpoint>

I have configured a DefaultFaultRule that will kick in if you try to deploy this proxy & hit it a few times. The AssignMessage policy simply sets the response payload to a custom message (as below). In this case it will give you a response like:

{
    "status": "default fault rule fired"
}

If we did not have the default rule, you should have seen something like:

{
    "fault": {
        "faultstring": "Spike arrest violation. Allowed rate : 2pm",
        "detail": {
            "errorcode": "policies.ratelimit.SpikeArrestViolation"
        }
    }
}

Hope this helps

defaultruleproxy-rev1-2015-05-11.zip

Former Community Member
Not applicable

As @Ozan Seymen mentioned if you have a RaiseFault policy in your fault handler, then the DefaultFaultRule won't fire