Accessing original error.content when creating a custom error response

I'm looking to append some basic Apigee created error details to a flow-hook based logging system intended to create standard logs without developer input. Our logging mechanism is implemented and I'd like to append the "error.content" and "error.message" values to this log (when they have value) so developers that have not built their own robust logging can at least get some idea what issue put their proxy in an error state. This is just bare minimum stuff as I cannot assume all developers will do this and it seemed like an easy solution.

 

However, what I am seeing is that when a FaultRule/RaiseFault modifies the response payload, that new payload overwrites the "error.content" value.

 

For example, here's the "error.content" value for a basic invalid API key fault:

 

 

 

{
    "fault": {
        "faultstring": "Invalid ApiKey",
        "detail": {
            "errorcode": "oauth.v2.InvalidApiKey"
        }
    }
}

 

 

 

This is pretty nice, but I don't expect every developer wants to use this so I fully expect someone at my org to use an AssignMessage/RaiseFault and create their own assuming something like this very basic approach:

 

 

 

<AssignMessage async="false" continueOnError="false" enabled="true" name="AM-Generate-Fault-Response">
    <DisplayName>AM-Generate-Fault-Response</DisplayName>
    <Set>
        <Payload contentType="application/json">
            {   "message": "You were not authorized"
            }
        </Payload>
    </Set>
    <AssignTo createNew="false" transport="http" type="response"/>
</AssignMessage>

 

 

 

 However, once this is done, my flow hook picks up "error.content" as:

 

 

 

{
   "message" : "You were not authorized"
}

 

 

 

It appears as though the error.content value becomes whatever the response message is.

Is there a way to retrieve that original error.content value without capturing it to a variable prior to changing the response?

If not, is there a way to at least build the "error code" value in the default response? Can I access the prefix with variables? On a somewhat related note, can I also access the name of the policy or other mechanism that put the proxy in an error state? 

0 0 42
0 REPLIES 0