A more complex example involves returning a custom FaultResponse payload, along with HTTP headers and an HTTP status code. In the following example the FaultResponse is populated with an XML message along with the value of single variable--the HTTP status code received by the API Platform from the backend service.

<RaiseFault> attributes

Set to true to specify that the policy should be run in a thread pool different from the pool servicing the request/response flow.

Note: This setting is only used for for internal optimization. Contact Apigee Support via the Support Portal for more information.

false

Optional

continueOnError

Set to false to return an error when a policy fails. This is expected behavior for most policies.

Set to true to have flow execution continue even after a policy fails.

false

Optional

enabled

Set to true to enforce the policy.

Set to false to "turn off" the policy. The policy will not be enforced even if it remains attached to a flow.

true

Optional

name

The internal name of the policy. Characters you can use in the name are restricted to: A-Z0-9._\-$ %. However, the Edge management UI enforces additional restrictions, such as automatically removing characters that are not alphanumeric.

Optionally, use the <DisplayName> element to label the policy in the management UI proxy editor with a different, natural-lanaguage name.

N/A

Required

<DisplayName> element

A natural-language name that labels the policy in the management UI proxy editor. If omitted, the policy name attribute is used.

<DisplayName>RaiseFault 1</DisplayName>

Default:

Policy name attribute value.

Presence:

Optional

Type:

String

<FaultResponse> element

(Optional) Defines the response message returned to the requesting client. FaultResponse uses the same settings as the AssignMessage policy type. See Assign Message policy.

<FaultResponse>/<Set>/<Headers> element

Sets or overwrites HTTP headers in the message variable specified with the <AssignTo> element. Note that the empty header <Set><Headers/></Set> does not set any header. This example sets the user-agent header to the message variable specified with the <AssignTo> element.

<IgnoreUnresolvedVariables> element

Usage notes

The API Platform enables you to configure custom exception handling using a policy of type RaiseFault.

The RaiseFault policy is a variation on the AssignMessage policy type. Like an AssignMessage policy, a RaiseFault policy generates a custom message in response to an error condition. You use RaiseFault to define a FaultResponse that is returned to the requesting app when a specific condition arises.

A FaultResponse can consist of HTTP headers, query parameters, and a message payload. These elements can be dynamically populated using variables, enabling you to craft FaultResponses that are tailored to specific failure conditions. Such tailored FaultResponses can be more useful to app developers and app end users than generic error messages or HTTP response codes.

When executed, the RaiseFault policy transfers the message Flow execution to the default ErrorFlow, which in turn returns the designated FaultResponse to the requesting client app. When the message Flow switches to the default ErrorFlow, no further policy processing occurs. All remaining processing Steps are bypassed, and the FaultResponse is returned directly to the requesting app.

Flow variables

Flow variables enable dynamic behavior of policies and Flows at runtime, based on HTTP headers, message content, or Flow context. The following predefined Flow variables are available after a RaiseFault policy executes. For more information about Flow variables, see Variables reference.

Variable

Type

Permission

Description

fault.name

String

Read-Only

Returns the fault name in the error and if not available, an empty string.

fault.type

String

Read-Only

Returns the fault type in the error and if not available, an empty string.

fault.category

String

Read-Only

Returns the fault category in the error and if not available, an empty string.

Error codes

This policy defines the following error codes. For guidance on handling errors, see Fault handling.