Re-using shared steps used in fault rules

I have a few proxies that have about 15 fault rules that executes one or more steps based on a certain condition. E.g.:

<FaultRule name="SpikeArrestViolation">
<Condition> (fault.name equals "SpikeArrestViolation") </Condition>
<Step> 
<Name>AssignMessage-ErrorFlow-TooManyRequest-Spike</Name>
</Step>

Most of these fault rules are common across the proxies as many of these are related to catching a fault and building a custom error response that follows the same format as the error responses coming from the backend services.

Is there any way I can keep these "Steps" in one place and reuse them in multiple proxies?

These are not part of a flow hence I'm not sure if shared flows or flow hooks would work.

0 6 162
6 REPLIES 6

@Krishna kumar Natarajan, please look at

https://community.apigee.com/articles/23724/an-error-handling-pattern-for-apigee-proxies.html Ozan describes a generic handler and look at David Mehi's git repo for a sample implementation.

Good answer, Rajeev!

@Dino-at-Google I am already following this practice of using Assign message to assign error codes, error text etc. and writing them into the response in a default fault rule.

My question though is different.

I'm maintaining the same Assign Message policies in multiple proxies - for example, an AssignMessage-InvalidToken is the same policy across all my proxies and I'd like to reuse them.

Is it possible to do this?

You can, in several different ways.

1. Use a shared flow and call to THAT to AssignMessage

2. Store the message template into a KVM and when you invoke AssignMessage, apply THAT.

This came as a realization to me but may be an obvious answer to others.

In addition to the best practice recommendation on fault rules configuration, my question was how can we share the steps under the fault rules between proxies.

Being called a Shared "Flow" I just assumed that these can be hooked only into Pre-flows, Flows and Post-flows but I realized later that you can as well call a shared flow under a fault rule or even within a default fault rule.

Yes, that's a good thing to point out. Thanks!