Flow variables not available in Post Client flow

I have a message logging policy in post client flow.

In this message logging policy i am reading few flow variables as mentioned below :

application={apiproxy.name} path={message.path} content = {message.content} error = {error.content}

I have few fault rules in place handling various error scenarios.

In case of error one of my fault rule is getting executed on basis of condition applied and using Raise Fault policy i am preparing a proper error body to be passed on to client.

But in case of error once my fault rule has executed and the control goes to Post Client flow i am not getting values for any of the variables i am reading in my message logging policy.

IS this behavior as per the design and i cant read any flow variables in case of error in Post Client flow or is there something missing in my configuration.

Is it at all possible to read these flow variables in Post Client Flow in case a error occurs and a fault rule is executed having a RAise Fault Policy

Solved Solved
0 7 1,078
1 ACCEPTED SOLUTION

Hi @asrivastava109 , both `message.content` and `error.content` are not available in PostClientFlow, it's the default behavior AFAIK, nothing wrong with your configuration.

I checked the asnwer posted by @Etienne Dippenaar should work, however it wont work if there's RaiseFault, as Default Fault Rule does not get executed even if there's <AlwaysEnforce>true</AlwaysEnforce> in place.

Here's text from documentation - https://docs.apigee.com/api-platform/fundamentals/fault-handling#creatingfaultrules-creatingadefault...

"However, there's one instance where this isn't the case. If a FaultRule other than the DefaultFaultRule invokes a Raise Fault policy, the DefaultFaultRule does not execute, even if the <AlwaysEnforce> element in the <DefaultFaultRule> tag is true."

What I would recommend using <AssignMessage> Policy instead <RaiseFault>, as you can also set the error (custom) payload/verb/status code using AssignMessage policy, as shown below;

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="MissingOrInvalidApiKeyErrorMessage">
    <DisplayName>MissingOrInvalidApiKeyErrorMessage</DisplayName>
    <Properties/>
    <Set>
        <Payload contentType="application/json" variablePrefix="%" variableSuffix="#">
            {
                "errors": [
                    {
                        "code": "<your custom code> or use %error.status.code#",
                        "message" : "<custom message>"
                    }
                ]
            }
        </Payload>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="message"/>
</AssignMessage>

In addition use the solution proposed by @Etienne Dippenaar, if you wish to capture error.content/message.content; I hope this helps;

View solution in original post

7 REPLIES 7

Hi,

I assume your message logging policy is added in your PostClientFlow, if not it will log it in-line and when an error occurs it will ignore it? Which is against best-practices.

If it is in your PostClientFlow, then I assume the following gets logged

application={apiproxy.name} path={message.path}

but the content parameters is empty when an error occurs

content ={message.content} error ={error.content}

I am not sure why it is happening but what I did to fix my issue is to add an AM policy in Proxy Endpoint

<DefaultFaultRule name="always-enforce-fault-rule">
        <Step>
            <Name>AM-SetBodyVariables</Name>
        </Step>
        <AlwaysEnforce>true</AlwaysEnforce>
</DefaultFaultRule>

That will create new variables

<DisplayName>AM-SetBodyVariables</DisplayName>
    <AssignVariable>
        <Name>e.message.content</Name>
        <Ref>message.content</Ref>
    </AssignVariable>
    <AssignVariable>
        <Name>e.error.content</Name>
        <Value/>
        <Ref>error.content</Ref>
    </AssignVariable>

You will then have to log the following in your policy

content ={e.message.content} error ={e.error.content}

@Etienne Dippenaar

Thanks for a prompt reply.

As i mentioned in my original question that i have Raise Fault policies in my Fault Rules.

As mentioned in the document if a error is thrown from FaultRule by using Raise Fault policy the DefaultRule does not execute even if you have <AlwaysEnforce>true</AlwaysEnforce>.

I tried the approach suggested by you but it didnt worked out for me because of above mentioned reason.

i have Raise Fault policies in my Fault Rules.

You don't need to do that, and probably should not do that. Just use AssignMessage. If the logic has transferred to FaultRules, there is already a fault that has been raised. To change the fault message or code, use AssignMessage. Don't use another RaiseFault.

@Dino-at-Google ♦♦

Thanks for the advice issue is resolved now after i have replaced Raise Fault with Assign Message in fault rules.

Hi @asrivastava109 , both `message.content` and `error.content` are not available in PostClientFlow, it's the default behavior AFAIK, nothing wrong with your configuration.

I checked the asnwer posted by @Etienne Dippenaar should work, however it wont work if there's RaiseFault, as Default Fault Rule does not get executed even if there's <AlwaysEnforce>true</AlwaysEnforce> in place.

Here's text from documentation - https://docs.apigee.com/api-platform/fundamentals/fault-handling#creatingfaultrules-creatingadefault...

"However, there's one instance where this isn't the case. If a FaultRule other than the DefaultFaultRule invokes a Raise Fault policy, the DefaultFaultRule does not execute, even if the <AlwaysEnforce> element in the <DefaultFaultRule> tag is true."

What I would recommend using <AssignMessage> Policy instead <RaiseFault>, as you can also set the error (custom) payload/verb/status code using AssignMessage policy, as shown below;

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="MissingOrInvalidApiKeyErrorMessage">
    <DisplayName>MissingOrInvalidApiKeyErrorMessage</DisplayName>
    <Properties/>
    <Set>
        <Payload contentType="application/json" variablePrefix="%" variableSuffix="#">
            {
                "errors": [
                    {
                        "code": "<your custom code> or use %error.status.code#",
                        "message" : "<custom message>"
                    }
                ]
            }
        </Payload>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="message"/>
</AssignMessage>

In addition use the solution proposed by @Etienne Dippenaar, if you wish to capture error.content/message.content; I hope this helps;

What I would recommend using <AssignMessage> Policy instead <RaiseFault>, as you can also set the error (custom) payload/verb/status code using AssignMessage policy,

YES. Do this.

Hi @Kuldeep Bhati

May I please know why message.content flow variable is not available in the PostClientFlow?