Raise Fault policy against Quota Violation

priyodas12
Participant I

Can we use Raise Fault Policy against Quota Violation?I had Tried with both accordingly but raise fault policy always getting skipped.

Solved Solved
0 6 586
1 ACCEPTED SOLUTION

@Priyobrato Das, Raise fault will not get executed when quota violation occurs. If you check the quota policy definitions, it will have a flag "continueOnError" set to false. The flow execution will stop once the quota violation occurs. You have two options to have custom error handling for quota violation

1. Define faultrules for quota policy execution failure. You can define the error handling policies in the faultrule. This is the recommended option as it allows to gracefully handle the error and provide custom error response to the consumer.

You can refer to the quota policy runtime errors in the docs - https://docs.apigee.com/api-platform/reference/policies/quota-policy

2. Change the setting for continueOnError to true and then execute the raise fault policy after checking for the condition if quota violation occurred using the flow variables. Note, here you would be explicitly throwing the error

View solution in original post

6 REPLIES 6

siddheshnaik
Participant II

You can handle fault in Fault rule using below condition:

(fault.name = "QuotaViolation")

Check this: https://docs.apigee.com/api-platform/fundamentals/fault-handling#execution

@Priyobrato Das, Raise fault will not get executed when quota violation occurs. If you check the quota policy definitions, it will have a flag "continueOnError" set to false. The flow execution will stop once the quota violation occurs. You have two options to have custom error handling for quota violation

1. Define faultrules for quota policy execution failure. You can define the error handling policies in the faultrule. This is the recommended option as it allows to gracefully handle the error and provide custom error response to the consumer.

You can refer to the quota policy runtime errors in the docs - https://docs.apigee.com/api-platform/reference/policies/quota-policy

2. Change the setting for continueOnError to true and then execute the raise fault policy after checking for the condition if quota violation occurred using the flow variables. Note, here you would be explicitly throwing the error

Yep, Agree, First option is the best practice. I would not recommend second option.

@Anil Sagar @ Google

Thank you for your quick response.

Actually I had tried with continueOnError="true" configuration,but while checking in trace once the quota exhausted then also raise fault skipped.Please find bellow key configuration I have applied.

<-Default flow config->

 <PreFlow name="PreFlow">
        <Request>
            <Step>
                <Name>Quota-1</Name>
            </Step>
            <Step>
                <Name>Raise-Fault-1</Name>
                <Condition>(fault.name ="QuotaViolation")</Condition>
            </Step>
        </Request>
        <Response/>
    </PreFlow>

<-Raise Fault config->

<FaultResponse>
        <Set>
            <Headers/>
            <Payload contentType="text/plain">Quota Exhusted!</Payload>
            <StatusCode>429</StatusCode>
            <ReasonPhrase>More Http Trigger </ReasonPhrase>
        </Set>
    </FaultResponse>

You would not test "fault.name" if continueOnError = true. Instead you would look at ... I think ... "quota.failed" or something like that.

sidd-harth
Participant V

@Priyobrato Das, Fault rules are defined using the tag <FaultRules>. You can "catch" the quota violation and assign whatever response message you like. For example:

<ProxyEndpoint name="default">
    <Description/>
    <FaultRules>
        <FaultRule name="quota-error">
            <Step>
                <Name>AssignMessage-QuotaFault</Name>
            </Step>
            <Condition>(fault.name ="QuotaViolation")</Condition>
        </FaultRule>
    </FaultRules>
    <PreFlow name="PreFlow">
        <Request>
            <Step>
                <Name>Quota-1</Name>
            </Step>
        </Request>
        <Response/>
    </PreFlow>
......