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.
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:
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.
{
"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": {}
}
}
}
{
"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": {}
}
}
}
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.
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: {}
}
}
}
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: {}
}
}
}