message logging after 400+ status code from target endpoint

Hi Apigeeks,

I would like to log 400+ status response codes to Loggly using the message logging policy.

I’ve setup a simple message logging policy (this writes a simple message to Loggly).

However this doesn’t get triggered when the target endpoint responds with an Error.

So I configured a fault rule to trigger this policy:

fault.name = “ErrorResponseCode”

LogActie

I got this info from:

https://community.apigee.com/questions/3332/policies-in-postflow-not-excecuted-when-request-at.html

However it is not working. Can anyone help me out on this one?

Dear @Sjoerd Nijland , Welcome to Apigee Community,

What does trace say ? Also, Can you check what is the fault name in the trace ? Keep us posted.

I don’t think “ErrorResponseCode” is actual fault name. Use the fault name based on error. If you would like to execute log policy no matter what, use default fault rule.

@Sjoerd Nijland Something like this should work for you. Also attaching the proxy for you to try this out yourself.

error-logs-rev1-2016-10-18.zip

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="default">
    <Description/>
    <FaultRules>
        <FaultRule name="ErrorResponseCode">
            <Condition>response.status.code >= 400</Condition>
            <Step>
                <Name>LogError</Name>
            </Step>
        </FaultRule>
    </FaultRules>
    <PreFlow name="PreFlow">
        <Request/>
        <Response/>
    </PreFlow>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <Flows/>
    <HTTPTargetConnection>
        <Properties/>
        <URL>https://httpbin.org</URL>
    </HTTPTargetConnection>
</TargetEndpoint>

Thanks. I now got it to work by attaching the policy at POST CLIENT FLOW instead (for using the message logging policy).

@Sjoerd Nijland @Anil Sagar

I just came across a similar use case and while tracing I noticed that backend errors, by default, will cause the proxy to enter the target fault flow and sets

fault.name = ErrorResponseCode

So now, in my fault flow, I can differentiate between faults raised in Edge and error responses from the backend, so I can then extract information from the Edge fault or from the backend response.