{tocify} $title={Table of Contents}
3. Test the flow with input which will fail and check the result. As can be seen error message is captured and assigned to a variable.
Introduction
No matter which technology/programming language you are using to build a solution, exception handling is an integral part.
And it should not be left unaddressed, as exceptions abnormally terminates the execution of the program.
An exception is an event(unplanned) that occurs while a program is executing and disrupts the flow of its instructions, example - invalid input or a loss of connectivity etc.
Exception handling ensures that the flow of the program doesn't break even when an exception occurs.
In Logic app too, we have provisions to implement exception handling.
But unlike other programming languages where you have specific exception objects in consideration when implementing exception handling, here broadly implemented as either of two
1. Connection Failure - Retry mechanism is used
2. All other exceptions - Run after property is used
Let's see how error scenario is handled and implemented
Individual Action's Exception Handling in Logic App
Every action which we add in workflow is a candidate for an error/exception.
Retry Policy in Logic App
A retry policy applies to intermittent failures, characterized as HTTP status codes 408, 429, and 5xx, in addition to any connectivity exceptions.
Four variants/types are available to choose from
If the retry policy definition is not specified explicitly, a fixed strategy is used with default retry count and interval values(The default is an exponential interval policy set to retry 4 times).
If you don't want to have retry, then to disable the retry policy, set its type to None.
So for any action which is trying to connect another application or is calling an api explicitly, you can configure retry policy
e.g.,
Go to settings of any connector like blob connector , sql connector , http connector etc. (open the ellipses menu (...), and select Settings)
Note, the retry interval is specified in the ISO 8601 format( P<period>T<time>).
The above interval says 02(period) and M(minutes), so retry will take place after an interval of 2 minutes.
Run After property in Logic App
Logic app is a JSON based DSL describing a dependency graph of actions and it is with the help Run after property available on each action (except trigger).
There are four status options available to use:
- is successful
- has timed out
- is skipped
- has failed
Except Trigger, all other Action(step) has dependency on some other action, and whenever you add new step in Logic app - Run after property is automatically set (on Successful Status of preceding step).
So, if you have to perform some action to handle failure/error/exception scenario, then you have to explicitly configure Run after property to look at Failed status/Timed Out of previous step.
How to get error message of a failed action in Logic App
Capturing error is helpful, as it gives clarity about the error. Which can be further logged somewhere, or respective stakeholders can be notified by sending email with the error message.
Below is snap, where I am configuring an action to capture the error msg of an Action named Set Variable
1. Configure Run After property - select has timed out and has failed status.
So this action will execute only if there is failure in Set Variable action
actions('Set_variable')['error']['message']
3. Test the flow with input which will fail and check the result. As can be seen error message is captured and assigned to a variable.
Based on requirement, you can log it or send email or take some other action.
It can be considered as Try..Catch block for individual Action.
Multiple Action's Exception Handling in Logic App - Using Scope
Whenever there is a need to encompass multiple steps in any programming language we use Try block and to catch exceptions of any of the steps in Try block we add Catch block.
How do you catch exceptions in logic app?
In Logic app we make use of one of the flow controls shape - Scope shape ( Logical grouping of actions).
When we use a scope to run set of actions (Multiple actions) and if any action in the scope fails or end unexpectedly, the scope is marked as "Failed" or "Aborted" respectively.
Under the scope, add a condition that checks the scope's failed status - add another scope which checks if status is Failed/Timed out i.e. configure Run after property of this scope to run on earlier scopes failed/timed out status.
How to catch exceptions in logic app - Example
To showcase how it can be done, have created a simple recurrence based logic app which has two scope - Try and Catch.
After trigger and Initializing variables have been added couple of actions in the Try scope, following it is the Catch Exception scope in which I am sending email with the Error message.
Testing
To make sure that there is an exception raised in Try scope, I configured incorrect url in HTTP action. And triggered the flow manually.
And as expected, an exception was raised in HTTP action and flow was passed on to Catch exception scope. Where an email was triggered with respective error message.
Following is the email received
An action failed. No dependent actions succeeded.
This error message is quite generic and it tells that something has gone wrong in Try scope but does not tell the specific details as to what was the actual error.
So how do we get error of an action/step which failed in the scope?
How to get actual error message of Scope in Logic App
In order to get the actual error message, we will need to make use of
- Filter Array action from Data operations and
- result() function
In the same logic app created above, we add Filter array in Catch Exception scope and input to it would be output of Try scope (which is an array of output of each step executed in it) - result('Try') , with a condition to check for the items in this array having status as failed.
And in Send Email action replace
actions('Try')['error']['message']
with
body('Filter_array')?[0]?['error']?['message']
Note:
The result() function returns the results only from the top-level actions and not from deeper nested actions such as switch or condition actions.
Testing
Tested again with the same incorrect url in http action, but this time received mail with actual error message (highlighted in yellow below)
When we add Scope and actions within it, the output of the scope consists of output of each step/action and is stored as an Array. So if there are 10 actions in scope then 10 items will be added (if all are succeeded) with a status as Success.
If there is failure in any of the action , then the status will be marked as Failed.
In the example in above step, we looked for the specific output which has status as failed from the array of output and for that we used Filter array.
Thus the output of Filter array consist only that item which has failed and in the succeeding action we used output of Filter array to get the actual error message.
Summary
In this article with the example we saw
- What is exception handling in logic app
- How to handle single action's exception using retry policy and Run after property
- How to handle multiple action's exception using Scope and Run after property
- How to get actual error message of Scope in Logic App using Filter Array and result Function
- How to send email from Logic App
If you have questions or suggestions, feel free to do in comments section below !!!
Do share if you find this helpful .......
Knowledge Sharing is Caring !!!!!
Learn More about Logic App
- How to configure Logic App Standard workflow behind Azure APIM
- How to Query Azure Table storage from Logic App | How to filter results of Azure Table storage from Logic App
- Understanding expressions in Logic Apps | Frequently used expressions in Logic Apps | What is expressions in Logic App
- How to use Logic app Run History | How to troubleshoot Logic App workflow execution
- Logic App and Slack - Sending messages to slack channel | Logic app and slack integration | Connecting Logic App to Slack channel
- How to access Application settings fields value from Logic app Standard workflow | Using Application settings as configuration store for Logic app standard workflow
- Developing Logic app standard workflow which uses Map locally and deploying to Azure
- Developing Logic App Standard Workflow Using Visual Studio Code | Create Logic App Standard Workflow Using Visual Studio Code
- Logic App - Xml to Json using Liquid Map | Append in Liquid Map
- How to use Azure Event Grid Custom Topic | Publishing and Subscribing from Azure Event Grid Custom Topic using Logic App
- Using Azure Storage Account Table as Config Store for Logic Apps | How to read and write from Logic App to Azure Storage Account Table
- Get Logic App Name in Logic App
- Difference between Logic App Consumption and Logic App Standard
- Getting Started with Logic App Standard | Overview of Logic App Standard | Basics of Logic App Standard
- How to find count of Logic App executions using Azure Portal
- Azure Functions vs Azure Logic App | Difference between Azure Functions and Azure Logic App
- Getting started with Logic App : Liquid Map | Using Liquid template in Logic app
- How to get actual error message of Scope in Logic App | Exception Handling in Logic app
- Interview questions and answers on Logic Apps | Interview questions for azure logic app developers
- How to execute Stored Procedure in Logic App | How to connect to SQL in Logic App
- How to get current date in logic app | How to format date time in Logic App
- BizTalk Developer getting started with Logic App
- Getting Started with Logic Apps - Fundamentals
- Getting Started with Logic Apps - Enterprise Application Integration
- Getting Started with Logic Apps - AS2
- Getting Started with Logic Apps - EDI X12 Fundamentals
- Getting Started with Logic Apps - XML to EDI X12
- Getting Started with Logic Apps - EDI X12 to XML
- Getting Started with Logic Apps - What happened to the Request?
- Inserting Multiple Records In On Prem SQL Using Logic App
- Inserting data in On Premises SQL Database using Logic Apps
- Installing and Configuring On Premises Data Gateway - By adding user to Active Directory
- XML Batching(Aggregation) in Logic App
- Batching(Aggregating) messages in Logic App
- Debatching(Splitting) JSON Message in Logic Apps - ForEach and SplitOn
- Debatching(Splitting) XML Message in Logic Apps - ForEach and SplitOn
- Securing Logic App with Azure Active Directory authentication
- Removing ns0: prefix from xml output from BizTalk/Logic app XSLT map
- Using Managed Identity in Logic Apps for Calling Active Directory Secured Function App
- Logic Apps : Fetching ISA and GS Segment Values From Interchange Envelope and Mapping
- Logic Apps : For Each Inside a For Each - Fetching values from field in an array inside an array
- How to configure Logic App Standard workflow behind Azure APIM
- How to Query Azure Table storage from Logic App | How to filter results of Azure Table storage from Logic App
- Understanding expressions in Logic Apps | Frequently used expressions in Logic Apps | What is expressions in Logic App
- How to use Logic app Run History | How to troubleshoot Logic App workflow execution
- Logic App and Slack - Sending messages to slack channel | Logic app and slack integration | Connecting Logic App to Slack channel
- How to access Application settings fields value from Logic app Standard workflow | Using Application settings as configuration store for Logic app standard workflow
- Developing Logic app standard workflow which uses Map locally and deploying to Azure
- Developing Logic App Standard Workflow Using Visual Studio Code | Create Logic App Standard Workflow Using Visual Studio Code
- Logic App - Xml to Json using Liquid Map | Append in Liquid Map
- How to use Azure Event Grid Custom Topic | Publishing and Subscribing from Azure Event Grid Custom Topic using Logic App
- Using Azure Storage Account Table as Config Store for Logic Apps | How to read and write from Logic App to Azure Storage Account Table
- Get Logic App Name in Logic App
- Difference between Logic App Consumption and Logic App Standard
- Getting Started with Logic App Standard | Overview of Logic App Standard | Basics of Logic App Standard
- How to find count of Logic App executions using Azure Portal
- Azure Functions vs Azure Logic App | Difference between Azure Functions and Azure Logic App
- Getting started with Logic App : Liquid Map | Using Liquid template in Logic app
- How to get actual error message of Scope in Logic App | Exception Handling in Logic app
- Interview questions and answers on Logic Apps | Interview questions for azure logic app developers
- How to execute Stored Procedure in Logic App | How to connect to SQL in Logic App
- How to get current date in logic app | How to format date time in Logic App
- BizTalk Developer getting started with Logic App
- Getting Started with Logic Apps - Fundamentals
- Getting Started with Logic Apps - Enterprise Application Integration
- Getting Started with Logic Apps - AS2
- Getting Started with Logic Apps - EDI X12 Fundamentals
- Getting Started with Logic Apps - XML to EDI X12
- Getting Started with Logic Apps - EDI X12 to XML
- Getting Started with Logic Apps - What happened to the Request?
- Inserting Multiple Records In On Prem SQL Using Logic App
- Inserting data in On Premises SQL Database using Logic Apps
- Installing and Configuring On Premises Data Gateway - By adding user to Active Directory
- XML Batching(Aggregation) in Logic App
- Batching(Aggregating) messages in Logic App
- Debatching(Splitting) JSON Message in Logic Apps - ForEach and SplitOn
- Debatching(Splitting) XML Message in Logic Apps - ForEach and SplitOn
- Securing Logic App with Azure Active Directory authentication
- Removing ns0: prefix from xml output from BizTalk/Logic app XSLT map
- Using Managed Identity in Logic Apps for Calling Active Directory Secured Function App
- Logic Apps : Fetching ISA and GS Segment Values From Interchange Envelope and Mapping
- Logic Apps : For Each Inside a For Each - Fetching values from field in an array inside an array
Tags:
Azure Logic Apps