How to handle 5xx errors from APIGEE Edge/ API Proxy

Not applicable

Hi, I know we can handle the 5xx response status codes from the target server. But not sure where we can write a code for 5xx response status codes from API Proxy or APIGEE Edge. Please advise. Thanks!

0 5 511
5 REPLIES 5

Former Community Member
Not applicable

Hi @Swapna you can use the Raise Fault policy to trap that condition and author your own code that you would like to return.

Thanks @Prithpal Bhogill. I have a requirement to send an email if the proxy endpoint is throwing 5xx errors. So, In my below example I believe, response.status.code is incorrect as we are not looking for target response.

Please advise what is the variable I need to use it here in this example.

Example:

<ProxyEndpoint name="default">

...

<FaultRules>

<FaultRule name="CheckResponseJS_rule">

<Step> <Name>SendAlert</Name> </Step>

<Condition>(response.status.code >= 500)</Condition>

</FaultRule>

</FaultRules>

</ProxyEndpoint>

Hi @Swapna. In what scenario you will get 5xx error from proxy endpoint? If you want to send email on specific error you can add Raise fault and use its "fault.name" variable in your condition.

adas
Participant V

@Swapna Here's one example that may help:

        <FaultRule name="InvalidQuota">
            <Condition>ratelimit.Quota.failed == "true"</Condition>
            <Step>
                <Name>CheckUsedCountQuota</Name>
            </Step>
            <Step>
                <Condition>sendEmail == "true"</Condition>
                <Name>Quota-SendMail</Name>
            </Step>
            <Step>
                <Name>InvalidQuota</Name>
            </Step>
        </FaultRule>

In the above example, I want to send out an email if the Quota is exceeded based on a condition "sendEmail = true". And then throw an error with the InvalidQuota policy. The InvalidQuota policy can look like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<RaiseFault enabled="true" continueOnError="false" async="false" name="InvalidQuota">
    <DisplayName>InvalidQuota</DisplayName>
    <FaultRules/>
    <Properties/>
    <FaultResponse>
        <Set>
            <Payload contentType="text/plain">You have exceeded the usage quota for the current time period</Payload>
            <StatusCode>429</StatusCode>
            <ReasonPhrase>Too Many Requests</ReasonPhrase>
        </Set>
    </FaultResponse>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</RaiseFault>

Thanks @Sonali and @arghya das.

I know about this but I'm not sure about what is the response we are getting back for proxy errors from Edge.

Suppose, In the attached report we are seeing 401 response code from Proxy. Total per day we have 291 proxy errors with response code 401. So, wanted to check a FaultRule to send an email if the response code is greater than or equal to 400 then will send an email to my support team. I don't want to RaiseFault to the clients. Let me know if you are not clear about the requirement.

So for this I'm not really sure what is the variable I need to use it. Thanks!

report.png