Try

Runs logic with built-in error handling and fallback behavior.

Use the Try policy to run a section of logic with built-in error handling. It lets you catch failures and return a fallback response or apply alternative logic when an error occurs.

For more information on the policy parameter descriptions, see DataPower Nano Gateway documentation.

Example of a Try policy in code view.

kind: try
apiVersion: api.ibm.com\v1
metadata:
  name: "try-sample"
  version: 1.0
  namespace: sample
spec:
  execute:
    # Normal execute block, allows all actions
    - $ref: sample:invoke-database:1.0
  catch: #optional
    # Is an array of errors+execute pairs allowed? If yes, what happens if there are 2 paris with empty "errors" definition?
    - errors: #optional -> if left out, will catch all errors
      - "BadRequestError" 
      - "CacheUnmetInputs"
      - "CacheUnmetOutputs"
      - "ConnectionError"
      - "CorsRejectError"
      - "CustomError"
      - "ForbiddenError"
      - "InternalError"
      - "JsonataError"
      - "JsonataNoMatchError"
      - "LimitExceededError"
      - "LuaScriptError"
      - "MethodNotAllowedError"
      - "NotFoundError"
      - "NotImplementedError"
      - "RedirectsExceeded"
      - "ParseError"
      - "TimeoutError"
      - "SqlInjectionFilterError"
      - "UnauthorizedError"
      - "ValidateError"
      execute:
          #handle catched error here
        - $ref: sample:set-custom-response:1.0
  finally: #optional
    #normal execute block allows all actions
    - $ref: sample:set-id-header:1.0