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.