Layer7 API Management

Expand all | Collapse all

How to send request timeout error from API proxy

Jump to Best Answer
  • 1.  How to send request timeout error from API proxy

    Posted 12-01-2017 05:32 AM

    Hi,

    We want to send request timeout error to the client application from api proxy for the below scenarios:
    API proxy is calling a back-end API, the proxy will send-out a request timeout error if it does not receive the response from back-end service within 5 seconds.

    Need guidance here - what are the properties to be configured and how to catch the error on the proxy to send a customized error details? Also want to know what will be the httpRouting.reasonCode property value.

    Regards.



  • 2.  Re: How to send request timeout error from API proxy

    Posted 12-02-2017 11:26 AM

    To ensure that the HTTP Routing assertion times out in the appropriate time you will need to change the settings on the Connections tab so it looks like the image below.

     

     

    Once you have done that you can use a branch to capture what the last audit value was and compare it against the standard output found for audit code 6005 and 9611 (Audit Detail Codes - CA API Gateway - 9.2 - CA Technologies Documentation ). I've included a sample policy to help get you started with the logic. As for your last question around which httpRouting.reasonCode will be returned it should be "-4 (Read timeout): One of packets being received from the URL took longer than the read timeout value to be received. The read timeout value is defined in the assertion properties." (Message Routing Context Variables - CA API Gateway - 9.2 - CA Technologies Documentation )

     

    <?xml version="1.0" encoding="UTF-8"?>
    <wsp:Policy xmlns:L7p="http://www.layer7tech.com/ws/policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2002/12/policy">
        <wsp:All wsp:Usage="Required">
            <wsp:OneOrMore wsp:Usage="Required">
                <L7p:HttpRoutingAssertion>
                    <L7p:ConnectionTimeout stringValue="300"/>
                    <L7p:MaxRetries intValue="0"/>
                    <L7p:ProtectedServiceUrl stringValue="http://foo.ca.com/communities"/>
                    <L7p:ProxyPassword stringValueNull="null"/>
                    <L7p:ProxyUsername stringValueNull="null"/>
                    <L7p:RequestHeaderRules httpPassthroughRuleSet="included">
                        <L7p:ForwardAll booleanValue="true"/>
                        <L7p:Rules httpPassthroughRules="included">
                            <L7p:item httpPassthroughRule="included">
                                <L7p:Name stringValue="Cookie"/>
                            </L7p:item>
                            <L7p:item httpPassthroughRule="included">
                                <L7p:Name stringValue="SOAPAction"/>
                            </L7p:item>
                        </L7p:Rules>
                    </L7p:RequestHeaderRules>
                    <L7p:RequestParamRules httpPassthroughRuleSet="included">
                        <L7p:ForwardAll booleanValue="true"/>
                        <L7p:Rules httpPassthroughRules="included"/>
                    </L7p:RequestParamRules>
                    <L7p:ResponseHeaderRules httpPassthroughRuleSet="included">
                        <L7p:ForwardAll booleanValue="true"/>
                        <L7p:Rules httpPassthroughRules="included">
                            <L7p:item httpPassthroughRule="included">
                                <L7p:Name stringValue="Set-Cookie"/>
                            </L7p:item>
                        </L7p:Rules>
                    </L7p:ResponseHeaderRules>
                    <L7p:SamlAssertionVersion intValue="2"/>
                    <L7p:Timeout stringValue="5000"/>
                </L7p:HttpRoutingAssertion>
                <wsp:All wsp:Usage="Required">
                    <L7p:ComparisonAssertion>
                        <L7p:CaseSensitive booleanValue="false"/>
                        <L7p:Expression1 stringValue="${audit.details.last.fullText}"/>
                        <L7p:Operator operatorNull="null"/>
                        <L7p:Predicates predicates="included">
                            <L7p:item dataType="included">
                                <L7p:Type variableDataType="string"/>
                            </L7p:item>
                            <L7p:item binary="included">
                                <L7p:Operator operator="CONTAINS"/>
                                <L7p:RightValue stringValue="reply within the timeout"/>
                            </L7p:item>
                        </L7p:Predicates>
                    </L7p:ComparisonAssertion>
                    <L7p:HardcodedResponse>
                        <L7p:Base64ResponseBody stringValue="RmFpbHVyZQ=="/>
                        <L7p:ResponseContentType stringValue="text/plain; charset=UTF-8"/>
                    </L7p:HardcodedResponse>
                </wsp:All>
            </wsp:OneOrMore>
        </wsp:All>
    </wsp:Policy>

     

    Sincerely,

     

    Stephen Hughes

    Director, CA Support



  • 3.  Re: How to send request timeout error from API proxy

    Posted 12-04-2017 05:26 AM

    Hi Stephen,

     

    Thanks for the detailed response.

    One query I have:

    Planning to use ${httpRouting.reasonCode} = -4 condition to throw error response, instead of comparing ${audit.details.last.fullText} with "timeout".

    Do you see any issue with this approach?

     

    Thanks.



  • 4.  Re: How to send request timeout error from API proxy
    Best Answer

    Posted 12-04-2017 10:41 AM

    The usage of either variable will work for what you are trying to capture.

     

    Sincerely,

     

    Stephen Hughes

    Director, CA Support