Azure Logic Apps execute multi-step workflows that interact with external APIs, databases, and services. Without structured error handling, you can’t react to failures, error context is lost, and retry policies cannot work correctly.

Why is this an issue?

Any step in a Logic App workflow can fail at runtime. The recommended pattern is to wrap actions inside a Scope action (the "Try" block) and follow it with a second Scope (the "Catch" block) that runs on failure, using the runAfter configuration with "Failed", "TimedOut", or "Skipped" statuses.

Without this pattern:

How to fix it in JSON templates

Wrap the business logic actions inside a Scope action (the "Try" block) and add a second Scope action (the "Catch" block) with a runAfter referencing the Try scope with at least one error status.

Code examples

Noncompliant code example

{
  "type": "Microsoft.Logic/workflows",
  "apiVersion": "2019-05-01",
  "name": "no-error-handling",
  "location": "[resourceGroup().location]",
  "properties": {
    "definition": {
      "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
      "actions": {
        "Get_items": {
          "type": "ApiConnection",
          "inputs": {
            "method": "get",
            "path": "/items"
          },
          "runAfter": {}
        }
      },
      "triggers": {}
    }
  }
}

Compliant solution

{
  "type": "Microsoft.Logic/workflows",
  "apiVersion": "2019-05-01",
  "name": "with-error-handling",
  "location": "[resourceGroup().location]",
  "properties": {
    "definition": {
      "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
      "actions": {
        "Try": {
          "type": "Scope",
          "actions": {
            "Get_items": {
              "type": "ApiConnection",
              "inputs": {
                "method": "get",
                "path": "/items"
              }
            }
          },
          "runAfter": {}
        },
        "Catch": {
          "type": "Scope",
          "actions": {
            "Log_error": {
              "type": "ApiConnection",
              "inputs": {
                "method": "post",
                "body": "Error occurred",
                "path": "/log"
              }
            }
          },
          "runAfter": {
            "Try": ["Failed", "TimedOut"]
          }
        }
      },
      "triggers": {}
    }
  }
}

How to fix it in Bicep

Wrap the business logic actions inside a Scope action (the "Try" block) and add a second Scope action (the "Catch" block) with a runAfter referencing the Try scope with at least one error status.

Code examples

Noncompliant code example

resource workflow 'Microsoft.Logic/workflows@2019-05-01' = {
  name: 'no-error-handling'
  location: resourceGroup().location
  properties: {
    definition: {
      '$schema': 'https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#'
      actions: { // Noncompliant
        Get_items: {
          type: 'ApiConnection'
          inputs: {
            method: 'get'
            path: '/items'
          }
          runAfter: {}
        }
      }
      triggers: {}
    }
  }
}

Compliant solution

resource workflow 'Microsoft.Logic/workflows@2019-05-01' = {
  name: 'with-error-handling'
  location: resourceGroup().location
  properties: {
    definition: {
      '$schema': 'https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#'
      actions: {
        Try: {
          type: 'Scope'
          actions: {
            Get_items: {
              type: 'ApiConnection'
              inputs: {
                method: 'get'
                path: '/items'
              }
            }
          }
          runAfter: {}
        }
        Catch: {
          type: 'Scope'
          actions: {
            Log_error: {
              type: 'ApiConnection'
              inputs: {
                method: 'post'
                body: 'Error occurred'
                path: '/log'
              }
            }
          }
          runAfter: {
            Try: [
              'Failed'
              'TimedOut'
            ]
          }
        }
      }
      triggers: {}
    }
  }
}

Resources

Documentation