Apigee - 4MV4D - Raise custom faults in API Proxy using Raise Fault Policy

In this video , We will see how to do custom validation & raise custom fault using raise fault policy in Apigee Edge.

Consider a scenario where you need to validate some business logic & raise a custom fault if validation fails. Implementing same in target server will be sometimes time-consuming process due to various reasons like complex server architecture, legacy system logic, complex lifecycle process.

Let's say you would like to send back 400 bad request error response to the client & raise a custom fault when validation fails. It's very simple to implement same in Apigee Edge by creating a proxy & using RaiseFaultPolicy.

Above proxy demonstrates how to restrict query params to target server & raise a fault if any query params present. You can modify the condition to suit your requirements using the flow variables.

For example,

API Request 1 - GET /hello - 200 OK

API Request 2 - GET /hello?name=Apigee - 400 BAD REQUEST

You can find the proxy source code used in above video here in github. Keep us posted if any queries.

Comments
praviningawale
Silver 1
Silver 1

Below is my API proxy URL
https://imp-123-api.azu.abc.com/v1/profile/workers/1234

In this URL I am passing 1234 which is employee number. This URL is working as expected and giving me details for employee number 1234.

If I enter below URL, it throws error 'Worker ID missing in the Client URL Request'. This I have configured using RaiseFault policy. I extract employee number and validate if it is not null.
https://imp-123-api.azu.abc.com/v1/profile/workers/

However, this RaiseFault policy does not work if I do not enter 'slash' at the end as below.
https://imp-123-api.azu.abc.com/v1/profile/workers

Is there a way to validate this URL. I still want to throw the error whether slash exist or not.

praviningawale
Silver 1
Silver 1

@Priyadarshi Ajitav Jena : Please suggest

Not applicable

I think you are using extract variable policy with workers/{id}

In this ignore unresolved variables true tag would be missing. Add that one. It should work.

Version history
Last update:
‎10-24-2016 06:13 AM
Updated by: