Full tutorial: Handling Errors and Retries in Azure Logic Apps.
Azure Logic Apps are the go-to service for business automation today because they allow you to automate workflows without writing extensive code.
However, when dealing with real-world scenarios, errors are inevitable, whether it’s a network issue, an unavailable API, or a missing resource.
When any of this happens, workflows should be able to recover from transient failures or at least notify the appropriate parties in case of an unrecoverable error.
In this post, I’ll walk you through how to manage errors and retries in Azure Logic Apps effectively.
We will cover the following:
Run After Configuration: Allows you to specify what should happen after an action succeeds, fails, or times out.
Retry Policies: Automatic retries can be configured for most actions if they encounter a transient error.
Scopes: Scopes group a set of actions together and handle success or failure states as a whole.
Run After Configuration
When to use: This is useful for defining what should happen next based on the outcome of a particular action whether success, failure or even timeout.
How to configure Run After Configuration:
In Azure Portal, navigate to your Logic App.
Add any action (e.g., HTTP call to an API) to your workflow.
Add another action to handle what happens when the first action fails. In this case, we can add a send email action to send an email if the result of the http action above fails.
Right click on the “send email to support group” action and select Run after.
Click on the Previous action: The http action: “Call customer API”
Select from the options: Is successful, Has timed out, Is skipped, Has failed
In this case, we select the Has failed option, which will tell the workflow to send an email when the http call fails.
Test:
Run or trigger the workflow, notice that the http action failed
Confirm that the email is sent.
Retries:
When to use: Transient errors like a network issue or an API being temporarily unavailable.
How to configure Retries:
In the Azure Portal, navigate to your Logic App.
Select the action where you want to configure retries.
Click on the Settings (gear icon) of the action.
Under Retry Policy, choose from:
- Default: Uses Azure’s default retry policy.
- None: No retries will be attempted.
- Exponential Interval: Retries will happen at exponentially increasing intervals (backoff).
- Fixed Interval: Retries happen after a fixed delay.
In this case, I configure 2 retries and a 5min interval between them.
In fixed interval policy, we must specify Count, which is the number of retries before failing the flow and Interval, specified in ISO 8601 format, which requires us to set the time between retries, e.g.: PT20S means 20 seconds, PT5H means 5 hours, etc.
Save the workflow.
Trigger or run the workflow and check how it performs.
Scopes.
When to use: Scopes allow you to group a set of actions and they are helpful for rolling back transactions, or sending notifications when something fails.
How to configure Scopes:
In Azure Portal, navigate to your Logic App
Add a Scope that will contain the actions:
From inside the Scope, click the Add Action symbol, and add the actions to be put in the Scope, previously created actions can also be dragged inside the Scope:
Set up a Run After for the Scope, so if any action in the Scope fails, the error is caught, and a compensating action (like logging or sending an email) can be performed. In this case, we send email by configuring a send email action to run after the Scope
Right click on the “send email to support group” action and select Run after.
Click on the Scope
Select from the options: Is successful, Has timed out, Is skipped, Has failed
In this case, we select the Has failed option, which will tell the workflow to send an email when any of the http actions in the Scope fails.
Save the workflow and Test it.
What about Logging & Monitoring in Azure Logic apps?
Azure Logic Apps integrates well with Azure Monitor and Application Insights. You can do the following:
Enable Diagnostics in your Logic App to log run history.
Set up Azure Monitor alerts for critical failures or repeated issues.
Use Application Insights to gain deeper insights into workflow performance and error rates.
We will take a look at this in a future post.
That is all for today & see you in the next one!