You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何捕获Azure Logic App中Scope动作执行失败的异常详情

Capturing Exception Details in Azure Logic App Scope & Workflow Example

Great question! When using Scopes in Azure Logic Apps for exception handling, capturing granular failure details from any action inside the Scope is totally doable with built-in expressions and workflow configuration. Let me walk you through how to set this up, plus share a complete workflow example.

Step 1: Configure Scope and Failure Trigger

First, structure your workflow with a Scope containing all your business actions. To handle failures, add an action right after the Scope and set its Run after property to Failed, Skipped, or Timed out (pick the ones relevant to your use case—usually Failed is the primary one you care about). This ensures the error-handling action only runs when something goes wrong inside the Scope.

Step 2: Capture Exception Details with Expressions

Azure Logic Apps provides the result() function to retrieve the execution status of all actions within a Scope. You can use this along with filter expressions to extract specific error details from the failed action(s). Here are some useful expressions:

  • Get all failed actions in the Scope:
    @where(result('Your_Scope_Name'), equals(item()['status'], 'Failed'))
    
  • Extract the error message from the first failed action:
    @first(where(result('Your_Scope_Name'), equals(item()['status'], 'Failed')))['error']['message']
    
  • Get the name of the failed action:
    @first(where(result('Your_Scope_Name'), equals(item()['status'], 'Failed')))['name']
    
  • Get the timestamp when the failure occurred:
    @first(where(result('Your_Scope_Name'), equals(item()['status'], 'Failed')))['startTime']
    

You can store these details in a variable, send them via email, log them to Azure Monitor, or whatever your error-handling workflow requires.

Step 3: Complete Workflow Example

Here’s a sample Logic App workflow JSON that demonstrates this setup. It includes a Scope with two actions (one intentional failure), then captures the error details and logs them:

{
  "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {},
  "triggers": {
    "Recurrence": {
      "type": "Recurrence",
      "recurrence": {
        "frequency": "Hour",
        "interval": 1
      }
    }
  },
  "actions": {
    "Business_Process_Scope": {
      "type": "Scope",
      "actions": {
        "Sample_Successful_Action": {
          "type": "Compose",
          "inputs": "This action runs successfully",
          "runAfter": {}
        },
        "Sample_Failed_Action": {
          "type": "Http",
          "inputs": {
            "method": "GET",
            "uri": "https://nonexistent.example.invalid"
          },
          "runAfter": {
            "Sample_Successful_Action": [
              "Succeeded"
            ]
          }
        }
      },
      "runAfter": {}
    },
    "Handle_Scope_Failure": {
      "type": "Compose",
      "inputs": {
        "Failed_Action_Name": "@first(where(result('Business_Process_Scope'), equals(item()['status'], 'Failed')))['name']",
        "Error_Message": "@first(where(result('Business_Process_Scope'), equals(item()['status'], 'Failed')))['error']['message']",
        "Failure_Timestamp": "@first(where(result('Business_Process_Scope'), equals(item()['status'], 'Failed')))['startTime']",
        "Full_Error_Details": "@first(where(result('Business_Process_Scope'), equals(item()['status'], 'Failed')))['error']"
      },
      "runAfter": {
        "Business_Process_Scope": [
          "Failed"
        ]
      }
    }
  },
  "outputs": {}
}

How This Works:

  • The Business_Process_Scope contains a successful Compose action and an intentional failed HTTP call to a non-existent URL.
  • The Handle_Scope_Failure Compose action runs only when the Scope fails. It uses expressions to pull key error details from the failed action and packages them into a structured output.
  • You can replace the Compose action with other actions like Send an email (V2) to notify your team, or Log to Azure Monitor for centralized error tracking.

Additional Tips

  • If multiple actions in the Scope could fail, use a For each loop with the where expression to process all failed actions individually.
  • Store error details in a variable first if you need to reuse them across multiple error-handling actions.
  • Enable Diagnostic Settings for your Logic App to send all execution logs to Azure Log Analytics, which makes debugging easier at scale.

内容的提问来源于stack exchange,提问作者Pradeep

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 14:07:33