policies in postflow not excecuted when request at target endpoint fails.

Hi,

I see that the policies in postflow are not executed when the target endpoint fails with status code 400, 404 or 500. Anyway i can make the policies execute if the target backend fails??

This is required for using a statistics collector policy to record how many request have failed, displaying the target status code in the custom reports dashboard.

All the success messages are recorded, but the failed messages are not getting showed up in the dashboard as the policy is not executed.

Thanks in advance.

K.Prashanthi.

Solved Solved
1 3 1,404
1 ACCEPTED SOLUTION

There are two ways of achieving this:

Handle faults in <FaultRules>

By default responses with 400+ response codes go into <FaultRules> section. You can put any policy that you want executing in these situations in there.

(Generally) in target/default.xml:

<FaultRules>
        <FaultRule name="ErrorResponseCode">
            <Condition>fault.name = "ErrorResponseCode"</Condition>
            <Step>
                <Name>DoSomething</Name>
            </Step>
        </FaultRule>
</FaultRules>

Configure Apigee to accept some response codes as success:

There is a configuration property which you can set in target/default.xml called "success.codes".

<HTTPTargetConnection>
	<Properties>
		<Property name="success.codes">2XX,3XX,400,5XX</Property>
	</Properties>
	<URL>...</URL>
</HTTPTargetConnection>

You can either specify the full response code or just say XX as **. These response codes will be accepted as success response and Apigee will continue executing policies from PostFlow, etc as it would for 200 responses.

View solution in original post

3 REPLIES 3

There are two ways of achieving this:

Handle faults in <FaultRules>

By default responses with 400+ response codes go into <FaultRules> section. You can put any policy that you want executing in these situations in there.

(Generally) in target/default.xml:

<FaultRules>
        <FaultRule name="ErrorResponseCode">
            <Condition>fault.name = "ErrorResponseCode"</Condition>
            <Step>
                <Name>DoSomething</Name>
            </Step>
        </FaultRule>
</FaultRules>

Configure Apigee to accept some response codes as success:

There is a configuration property which you can set in target/default.xml called "success.codes".

<HTTPTargetConnection>
	<Properties>
		<Property name="success.codes">2XX,3XX,400,5XX</Property>
	</Properties>
	<URL>...</URL>
</HTTPTargetConnection>

You can either specify the full response code or just say XX as **. These response codes will be accepted as success response and Apigee will continue executing policies from PostFlow, etc as it would for 200 responses.

Thank you @Ozan Seymen, able to execute the policies in postflow now.

Also a very useful way to ensure that CORS headers are applied to server error responses!