Flow level errors for urls pattern

Not applicable

I have an API proxy with 2 conditional flows (accepting POST on /customers/{value of customerId} ) in proxy endpoint and base path of /abc/xyz in http proxy endpoint. I want my API proxy to throw errors (400 bad request), if user POST on following url patter

just /abc, /abc/xyz or /abc/xyz/customers

By default API proxy just return the request payload with HTTP 200 (kind of loopback) ,if URL has one of those patterns.

How can this be implemented ?

Thanks,

1 7 124
7 REPLIES 7

Not applicable

You can have a flow at the end of all the end other flows with no condition and have that flow return a 404 or 400.

If none of the conditions in the above flow are met, this will be executed and the client will end up getting the appropriate error message instead of a 200 and letting the request pass to the backend.

like this:

<Flow name="unknown-resource">
            <Description>Unknown Resource</Description>
            <Request>
                <Step>
                    <Name>unknown-resource</Name>
                </Step>
            </Request>
            <Response/>
        </Flow>

and your unknown-resource policy will look like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<RaiseFault async="false" continueOnError="false" enabled="true" name="unknown-resource">
    <DisplayName>unknown-resource</DisplayName>
    <FaultResponse>
        <Set>
            <StatusCode>404</StatusCode>
            <ReasonPhrase>Resource not found.</ReasonPhrase>
        </Set>
    </FaultResponse>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</RaiseFault>

The sequence of the flows is important, the flow without any condition should be the last of your flows in your proxy xml

I use this pattern in virtually every API Proxy I configure on Apigee Edge.

The final Flow, with no Condition, is like a "default" case in a switch statement.

Hi

Please look at this post which might help you

Thanks for input, I implemented a thrid conditional flow as Sai suggested

After removing <Condition>(proxy.pathsuffix MatchesPath "/")</Condition> from the flow handler to reject the messages with weird urls.

/abc/xyz

/abc/xyz/order

the above two failed with 404 as I attached raise fault policy to this third flow so was expected and transaction appeared in trace.

while url "/abc" generated loopback response , no transaction appears in trace as if transaction never reach any of APigee flow.

So one of the downside of placing such flow would be request messages with unexpected uri will be counted as actual transaction in Apigee edge.

If the basepath of your API Proxy is /abc/xyz, only the requests with and after that base path (like /abc/xyz, /abc/xyz/foo) will be captured/counted as the ones belonging to that API Proxy. This classification is done by the Apigee Runtime Servers, before the request is processed by the API proxy. You will see only those in your trace for that API Proxy.

Other requests may be going to other API Proxies or you should get a error (404) if no API Proxies are listening to the URL you are requesting. (/abc) in this case