How to log the additional information displayed in the error phase of the trace screen?

Not applicable

Posting this on behalf of a customer:

In the Trace screen, the following information logged in the error phase. This error here is caused intentionally. error The Service is temporarily unavailable type ErrorPoint state TARGET_REQ_FLOW error.class com.apigee.messaging.adaptors.http.HttpAdaptorException error.cause Connection refused Identifier fault In error handler, the string "The Service is temporarily unavailable" is shown, but there is not any Flow Variables that expose the error.cause string given above. This is the really helpful information. Is there a way to be able to log this information. Is there anyway to get at this type of detailed information for failures to the back end?

--SF908266--

0 3 942
3 REPLIES 3

adas
Participant V

@Aravind Kumar Tadakamalla The following flow variables are populated for errors:

- error.content

- error.message

For other flow variables refer to the variables reference in the docs: http://apigee.com/docs/api-services/reference/vari...

Customers can use fault rules to give out custom error responses, by using these flow variables and populating them in the response payload. For example:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<RaiseFault async="false" continueOnError="false" enabled="true" name="ReturnGenericError">
    <DisplayName>ReturnGenericError</DisplayName>
    <Properties/>
    <FaultResponse>
        <Set>
            <Headers/>
            <Payload contentType="text/plain">
                {error.message}: {error.content}
            </Payload>
            <StatusCode>500</StatusCode>
            <ReasonPhrase>Server Error</ReasonPhrase>
        </Set>
    </FaultResponse>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</RaiseFault>

This RaiseFault policy captures the error.message and error.content and populates in the response payload to be sent to the client. This can be called as part of the default fault rule like below:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="default">
    <Description/>
    <PreFlow name="PreFlow">
        <Request/>
        <Response/>
    </PreFlow>
    <Flows/>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <HTTPTargetConnection>
        <URL>http://myapis.com/apigee/target</URL>
    </HTTPTargetConnection>
    <DefaultFaultRule name="fault-rule">
        <Step>
            <Name>ReturnGenericError</Name>
        </Step>
        <AlwaysEnforce>true</AlwaysEnforce>
    </DefaultFaultRule>
</TargetEndpoint>

In addition to this customers can also use the message logging policy to log the errors to local disk or syslog in a similar way. In that case instead of (or along with) the RaiseFault policy they might need to have a message logging policy which captures and logs the various errors.

for some reason, the error.content variable (or any other error variable) are not filled for me when I'm accessing these in a javascript policy. The JS Policy is located in the DefaultFaultRule flow.

I'm accessing it via:

var errorcontent = context.getVariable('error.content');

The error that I generated is an incorrect Api key...

How to ensure no matter what, I always have access to the error.content or error.message variable?

No use of error.content or error.message. really error.cause is giving actual error message. i dont know why apigee missed it out to include it as flow variable.