Get Original status code received from backend server.

Here is a snippet of my target-endpoint configuration,

<TargetEndpoint name="default">
    <Description/>
    <FaultRules>
        <FaultRule name="convertErrorsToSuccess">
            <Step>
                <Name>AssignMessagesmoothOutErrors</Name>
            </Step>
            <Condition>response.status.code != 200</Condition>
        </FaultRule>
    </FaultRules>
....

As, you can see I have attached an AssignMessage Policy in the FaultRule to handle non 200 responses. Here it goes,

<AssignMessage async="false" continueOnError="false" enabled="true" name="AssignMessagesmoothOutErrors">
    <DisplayName>AssignMessage.smoothOutErrors</DisplayName>
    <Copy/>
    <Set>
        <Payload contentType="application/json">
            \{"error": "There was some error at backend.", "originalStatusCode" : {message.status.code}}
        </Payload>
        <StatusCode>200</StatusCode>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="response"/>
</AssignMessage><br>

As part of payload, I want to send back the original status code received from backend. Above, configuration gives me '200' as a status code.

I'm very new to Apigee. Please help me out.

Solved Solved
0 3 1,888
1 ACCEPTED SOLUTION

Does the same variable used in the condition work? (I haven't tested.)

response.status.code

If that doesn't work (I expect it would), you should be able to capture the status code via assignvariable before handling it the fault rule and then use the variable you stored it in to set originalStatusCode.

View solution in original post

3 REPLIES 3

Does the same variable used in the condition work? (I haven't tested.)

response.status.code

If that doesn't work (I expect it would), you should be able to capture the status code via assignvariable before handling it the fault rule and then use the variable you stored it in to set originalStatusCode.

Yes, it works just fine in 'Condition'. Let me try to set one variable and use it in Payload.

Yep, it worked. It was so simple. Darn! Anyway, thanks @Carlos Eberhardt