Question

I have an Apigee proxy that has two resources (/resource1 and /resource2). If tried to access /resource3. How do I return a 404 error instead of the Apigee default fault?

Apigee displays the below fault string:

{
    "fault": {
        "faultstring": "The Service is temporarily unavailable",
        "detail": {
            "errorcode": "messaging.adaptors.http.flow.ServiceUnavailable"
        }
    }
}

Thanks

Was it helpful?

Solution

Currently the way flows work in apigee this way - It parses through your default.xml (in proxy) and tries to match your request with one of the flow either through the path-suffix like "/resource1, /resource2" or VERB or any other condition you might have. If it does not find any matching condition, it throws the error like above.

You can add a special flow which will be kicked in if the condition matches none of the valid flows you have. You can add a raisefault policy in that flow and add a custom error response through that flow.

enter image description here

OTHER TIPS

A better solution is to: be sure to define something in the base path of all Proxy APIs

create an additional Proxy API called "catchall" with a base path of "/" and with just a Raise fault throwing a 404

Apigee execute Proxy APIs from longest Base Path to shortest; the catchall will run last and always throw back a 404

I just want to clarify Vinit's answer. Vinit said:

If it does not find any matching condition, it throws the error like above.

Actually, if no matching flow condition is found, the request will still be sent through to the backend. The error you mentioned:

{
    "fault": {
        "faultstring": "The Service is temporarily unavailable",
        "detail": {
            "errorcode": "messaging.adaptors.http.flow.ServiceUnavailable"
        }
    }
}

was returned after attempting to connect to the backend without matching a flow.

Vinit's solution to raise a fault to create the 404 is the best solution for your requirements.

In some cases, however, it is appropriate to pass all traffic through to the backend (for example, if you don't need to modify each resource at the Apigee layer, and you don't want to have to update your Apigee proxy every time you add a new API resource). Not matching any flow condition would work fine for that use case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top