Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to pass simple error information to the proxy Flow from exceptions/faults in Java callouts?

Not applicable

The cookbook samples aren't very good. I'm simply trying to pass some simple error info like error code, text from Java class to edge policy. Not working. Any samples out there?

Solved Solved
2 2 1,015
1 ACCEPTED SOLUTION

If you want to return error code/message back from the Java class, set it to the MessageContext in Exception block.

In the following example, I am returning a custom "error_code" and "error_msg" back from the java class.

catch (Exception e) {
	messageContext.setVariable("error_code", 9999);
	messageContext.setVariable("error_msg", "City info is missing");
	return ExecutionResult.ABORT;
}

Then update the RaiseFault policy to use the error code and error message -

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<RaiseFault name="Fault.MissingCityName">
    <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
    <FaultResponse>
        <Set>
            <Headers/>
            <Payload contentType="application/xml">
                <error>
                    <httpResponseCode>409</httpResponseCode>
                    <errorCode>{error_code}</errorCode>
                    <errorMessage>{error_msg}</errorMessage>
                </error>
            </Payload>
            <StatusCode>409</StatusCode>
            <ReasonPhrase>Conflict</ReasonPhrase>
        </Set>
    </FaultResponse>
</RaiseFault>

View solution in original post

2 REPLIES 2