Conditional error processing

The Conditional error processing policy handles exception messages generated during runtime and enables you to define appropriate responses.

This policy lets you return a custom error message along with the native provider’s service fault to the calling application when a fault is received from the provider. You can configure conditions and use variables to craft dynamic, user-friendly error messages tailored to specific scenarios.

In IBM API Studio, this policy is identified by the kind ErrorProcessing.

Example of an Conditional error erocessing policy:

kind: ErrorProcessing
apiVersion: api.ibm.com\v1
metadata:
  name: httpbin
  namespace: foo
spec:
  condition: |
    "(${response.headers.test} equals test1) or
        (${request.headers.test} not-equals ${request.payload.jsonPath[$.customer.name]})"
  pre-processing:
    xsl:
      - feature:
         - name: test
           value: value
        $path: ./a/a.xsl
        content: sdsd
  transformations:
    set:
      - key: ${response.headers.h2}
        value: test4
      - key: ${request.query.q2}
        value: ${response.payload.jsonPath[$.customer.name]}
    setPayload:
      content-types:
        - application/json: |
            {
                "empid":"1"
            }
        - application/xml: |
            <test></test>
        - text/plain: |
            "This is a plain content"
      default-content-type: application/json
      xsl:
        - feature:
            - name: test
              value: value
          $path: ./a/a.xsl
          content: sdsd
    namespaces:
      - prefix: ps1
        URI: http://test.com
      - prefix: ps2
        URI: http://test2.com
    sendNativeError: true
  post-processing:
    xsl:
      - feature:
         - name: test
           value: value
        $path: ./a/a.xsl
        content: sdsd

For the ErrorProcessing policy kind, configure these specifications:

Type Description
spec This denotes various policy properties you can configure for the policy.
You can configure the following policy property:
  • conditions. Conditions are used to specify when the policy has to be executed. You can add multiple conditions with logical operators. Provide the condition in the format: {set} <operator> {value} <condition> {set} <operator> {value}

    You can use the following conditions:

    • and. Transforms the error responses that comply with all the configured conditions.
    • or. Transforms the error responses that comply with any one configured condition.

    You can use the following operators:

    • Equals
    • Not equals
    • Contains
    • Not Contains
    • Exists
    • Not Exists
    • Range
    • Greater Than
    • Less Than
  • pre-processing. Defines how the error response is processed before the policy applies its transformations.
    • xsl. Provide the XSLT file and the features you want to use to transform the service error response. Specify each XSLT feature name with its corresponding value. Provide the file path of the XSLT document and include its content.
  • transformations. Defines the transformations applied to the error response. You can configure the following:
    • set. Customizes the headers included in the error response. Provide the key as a variable reference and the value as either plain text or a variable reference.
    • setPayload. Defines how the payload is transformed. You can configure the following:
      • content-types. Specifies the payload content types to transform. You can specify one of the following content types: application/json, application/xml, text/plain.
      • xsl. Provide the XSLT file and the features you want to use to transform the service error response. Specify each XSLT feature name with its corresponding value. Provide the file path of the XSLT document and include its content.
    • namespaces. Defines the namespaces used during transformation. You can add multiple namespace prefixes and URIs.
      • prefix. Represents the namespace prefix used in payload expressions.
      • URI. Represents the namespace URI used in payload expressions.
    • sendNativeError. Enables sending the native error instead of a custom error when a transformation or policy operation fails.
  • post-processing. Defines how the error response from the native service is processed before it is returned to the application.
    • xsl. Provide the XSLT file and the features you want to use to transform the service error response. Specify each XSLT feature name with its corresponding value. Provide the file path of the XSLT document and include its content.