Pradeep
Pradeep

Reputation: 5520

How to capture the exception details in case of any action failed in the Scope action in Azure Logic App

I have implemented Azure Logic App to execute my business flow. For exception handling, I used Scope action. But I want to capture exception details in case of any action failed in the Scope.

Sample logic app flow to handle the exceptions:

enter image description here

Upvotes: 1

Views: 1052

Answers (1)

Harshita Singh
Harshita Singh

Reputation: 4870

The result() function provides context about the results from all the actions in a scope. The result() function accepts a single parameter, which is the scope's name, and returns an array that contains all the action results from within that scope. These action objects include the same attributes as the actions() object, such as the action's start time, end time, status, inputs, correlation IDs, and outputs. To send context for any actions that failed within a scope, you can easily pair a @result() expression with the runAfter property.

To run an action for each action in a scope that has a Failed result, and to filter the array of results down to the failed actions, you can pair a @result() expression with a Filter Array action and a For each loop. You can take the filtered result array and perform an action for each failure using the For_each loop.

Here's an example, followed by a detailed explanation, that sends an HTTP POST request with the response body for any actions that failed within the scope "My_Scope":

"Filter_array": {
   "type": "Query",
   "inputs": {
      "from": "@result('My_Scope')",
      "where": "@equals(item()['status'], 'Failed')"
   },
   "runAfter": {
      "My_Scope": [
         "Failed"
      ]
    }
},
"For_each": {
   "type": "foreach",
   "actions": {
      "Log_exception": {
         "type": "Http",
         "inputs": {
            "method": "POST",
            "body": "@item()['outputs']['body']",
            "headers": {
               "x-failed-action-name": "@item()['name']",
               "x-failed-tracking-id": "@item()['clientTrackingId']"
            },
            "uri": "http://requestb.in/"
         },
         "runAfter": {}
      }
   },
   "foreach": "@body('Filter_array')",
   "runAfter": {
      "Filter_array": [
         "Succeeded"
      ]
   }
}

For more details about this suggestion, you can visit Get context and results for failures in Scope

Upvotes: 2

Related Questions