unable to extract variables from extract policy for negative scenario

Not applicable

I am facing an issue while extracting the variables in negative scenario. Below is my response format which i got from trace , {"message":"Id '2337' not found.","codeDescription":"NotFound","code":"*****"}.I am unable to extract any of those variabls in extract policy and the extract policy is not coming in the trace. The same thing is working for positive scenario. The extract policy is visible in trace and able to see the variable in trace. I checked the content-type - it is application/json . Please help out.

Solved Solved
0 11 453
1 ACCEPTED SOLUTION

HI @Lavanya Srinivasan

By default, Apigee Edge treats HTTP code 4XX or 5XX as errors, and it treats HTTP code 1XX, 2XX, 3XX as success.

If you want to add HTTP code 4xx to the list of default success codes, set this property in the Target End point proxy config as:

<Property name="success.codes">1xx,2xx,3xx,4xx</Property>

More info here

Once you have added that to your proxy config, then the policy to extract the response for negative scenarios will get executed. You should be able to trace this. The default behavior is that it will throw an error if the target system returns a 4xx which will by pass your policies in the Response flow.

Try this out and let me know if it works.

View solution in original post

11 REPLIES 11

Not applicable

Not applicable

Hello @Lavanya Srinivasan,

Can you please share the code of extract variable policy here ?

Please see the below extract variable code ,

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Error-Codes">

<DisplayName>Extract Error Codes</DisplayName>

<Properties/>

<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>

<JSONPayload>

<Variable name="message">

<JSONPath>$.message</JSONPath>

</Variable>

</JSONPayload>

<Source clearPayload="true">response.content</Source> </ExtractVariables>

Hi @Lavanya Srinivasan,

Is this the error from backend? If so is the backend responding with http error status code like 400 or 500?

I am sending invalid input parameters and getting the response from backend server with status code as 404 , from the response i need to extract the variables and sent it across to my consumer.

Not applicable

Make sure you have the variables defined in the ExtractVariables Policy for the negative scenario as well if it is the same policy being used in the positive scenario, in case the response json are different in each scenario. Also, Trace UI does not usually show the variables extracted from ExtractVariables Policy until they are subsequently used/referred to in a downstream policy. They will be visible in the downstream policy if read or assigned.

For testing purpose, i have just changed the json variable for positive scenario, and able to see the extract policy in the trace and the variable value in the variable section in the trace. again i changed back to json variable to negative scenario, in that case i m unable to see the policy itself in the trace.

HI @Lavanya Srinivasan

By default, Apigee Edge treats HTTP code 4XX or 5XX as errors, and it treats HTTP code 1XX, 2XX, 3XX as success.

If you want to add HTTP code 4xx to the list of default success codes, set this property in the Target End point proxy config as:

<Property name="success.codes">1xx,2xx,3xx,4xx</Property>

More info here

Once you have added that to your proxy config, then the policy to extract the response for negative scenarios will get executed. You should be able to trace this. The default behavior is that it will throw an error if the target system returns a 4xx which will by pass your policies in the Response flow.

Try this out and let me know if it works.

Will try this and get back.

One more alternative from the BEST solution (if you do not want to change the success codes) provided by @Sai Saran Vaidyanathan, would be to add a similar policy in the Fault Flow. So, that whenever there is an error, the fault flow would be executed and the extract variable policy that you have there, would give you the desired result.

Thanks for the solution @Sai Saran Vaidyanathan . after setting that property it is working !!!.