Set Error response back to the client with out hitting target.

Not applicable

Hello all,

I have an api proxy. I am using service call out policy to get one Boolean value from another target. and Using Extract variable policy to assign the value. added in Proxy end point Pre flow

Based on value I need to call my target url. if value is false i dont want to hit my target url. with out hitting target is should return error to the client.

I m setting my target url in JavaScript and added into target endpoint pre flow. if value is true than hit JavaScript policy should run.

context.setVariable("target.url","http://*****************");

if value is false from their only revert back to the client.

Please help.

Solved Solved
0 5 737
1 ACCEPTED SOLUTION

@Madhav , As per my understanding, your requirement is as below:

  • Call out to target 1
  • Extract the response and check the value
  • If true then call out to target 2
  • If false then throw an exception

If my understanding is correct then you can implement as follows:

  1. Add SC policy in preflow to call out target 1
  2. Add extract variable policy in preflow to extract the response parameters
  3. Add raise fault policy in preflow with a condition on the extracted flag value
  4. Add SC policy in postflow to callout target 2

View solution in original post

5 REPLIES 5

@Madhav ,

You can use raisefault policy to throw required error response back to client if you don't get required value from service callout. This will move the API proxy processing to fault rules section and will not call any target endpoint there after. Try that way and see if it works.

Thanks,

Santosh

@Madhav , As per my understanding, your requirement is as below:

  • Call out to target 1
  • Extract the response and check the value
  • If true then call out to target 2
  • If false then throw an exception

If my understanding is correct then you can implement as follows:

  1. Add SC policy in preflow to call out target 1
  2. Add extract variable policy in preflow to extract the response parameters
  3. Add raise fault policy in preflow with a condition on the extracted flag value
  4. Add SC policy in postflow to callout target 2

@Mahammad Feroz how would you do step 3 in the implementation?

Raise fault is a policy which can be added to any flow with one or more cnditions.

https://docs.apigee.com/api-platform/reference/policies/raise-fault-policy#top_of_page

Not applicable

Thanks santosh