How to handle errors in Power Automate

When I started building serious flows with Power Automate, it never occurred to me that I should add error handling to them. I was simply hoping they would always work, occasionally checking for any failed flow runs.. And we are talking about very complex, business critical flows in production…
However, flows do fail. Fortunately, it’s easy to incorporate simple error handling into them.

In this blog post, I will guide you through simple Power Automate error handling while also offering ways to elevate your error handling to the next level:
- Level 1: Easy and/or lazy – This is the bare minimum for error handling
- Level 2: Some assembly required – Improving the level 1 error handling to make it more practical
- Level 3: Make it pretty – Totally optional, but can give you joy if you enjoy pretty things
So, whether you prefer an easy approach, don’t mind some assembly, or simply enjoy adding beauty to functionality, this blog post has you covered.
Level 1: Easy and/or lazy
Let’s start with the basics: how to react to errors in your flow!
Actions in Power Automate have “Configure run after” settings:

By default, an action is executed if the previous action is succesful. But we can utilize these settings to configure an action to run if the previous action fails.
To implement a simple error handling in to your flow, add the desired “after failure” actions inside a new scope (Scope is an awesome action that helps you to group actions). In my case, I prefer to receive notifications via Teams.
But why include a Terminate action? Without this action, the end result of the flow run would be considered successful (since the error handling actions were indeed executed successfully). By including the Terminate action, it becomes easier to identify failed flow runs in the run history later on.

Now that we have our actions, we can configure the settings in the scope level.

I also have my previous actions enclosed within a scope. If you’re not already using scopes to organize your actions, I highly recommend starting now. Trust me, I’m a professional. The previous scope (or action) is automatically displayed, and you can configure your scope to run if the previous scope or action has failed.

The ‘run after failure’ is visually represented in the flow by a red arrow:

This is how the flow run looks when it fails:

Level 2: Some assembly required
Wouldn’t it be nice if you could simply click to open the failed flow run directly from the notification? Well, this can be easily accomplished with the workflow() expression!

To extract the workflow details, we can use the Parse JSON action. If you are not familiar with the Parse JSON action, my API blog post gives a bit more detailed instructions.

Here’s the schema:
{
"type": "object",
"properties": {
"name": {
"type": "string"
},
"tags": {
"type": "object",
"properties": {
"flowDisplayName": {
"type": "string"
},
"environmentName": {
"type": "string"
}
}
},
"run": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
}
}
}
We still need to put everything together to form the URL to the flow run:

https://make.powerautomate.com/environments/{ENVIRONMENT-ID}/flows/{FLOW-ID}/runs/{RUN-ID}
It doesn’t have to be this fancy, though. The only component that needs to be dynamic in the URL is the run name. This simplifies duplicating flows or moving them between environments.
If your flow is inside a solution, you will need a different base for your URL. Unfortunately, the Workflow() expression does not provide the solution ID. You either have to input it manually or use an environment variable.
https://make.powerautomate.com/environments/{ENVIRONMENT-ID}/solutions/{SOLUTION-ID}/flows/{FLOW-ID}/runs/{RUN-ID}
Note that the Teams action does not directly support custom URLs unless you use HTML. To do so, switch to HTML mode. Here is the HTML syntax for creating links:
<a href="url">link text</a>

Level 3: Make it pretty
If you’ve come this far with your error handling, why not make it pretty as well?
You can easily create your own esthetically pleasing adaptive cards using Adaptive Card Designer. Feel free to unleash your creativity, but don’t forget to include the flow name and a button to open the flow run.

Once you’re done designing your adaptive card, copy the JSON code from the card payload editor and paste it into the ‘Post card in a chat or channel’ Teams action (note that this is a different Teams action than before).
Now the only remaining task is to replace the flow name and URL with dynamic content:

This is how my error message looks in Teams. It’s definitely prettier now.

Bonus tip: How to make flows fail?
This is not something you typically need to know, but when experimenting with error handling for the first time, you might actually want your flows to fail for testing purposes. But deliberately causing flows to fail can be surprisingly tricky to figure out. Here’s one easy way to force your flow to fail:

The SharePoint item ID must be a whole number, but in this case, I am using text instead. The update action itself does not accept text as an input, but you can easily overcome this by using the Compose action.
Thank you for the great explanation.
I already use scopes and this kind of error handling.
However I do use a switch function to set vars like environment before making the link.
I can now indeed improve and make the flow and notification more pretty.
Could you explain how the ‘Terminate’ action in Power Automate’s error handling strategy helps in identifying failed flow runs?
Using the ‘Terminate’ action for error handling can help you to identify failed flow runs more easily, because it will change the status of the flow run from ‘Succeeded’ to ‘Failed’. By default, Power Automate considers a flow run as successful if all the actions in the flow are executed, regardless of their individual outcomes. However, this might not reflect the actual business logic or expectations of your flow. For example, if your flow is supposed to send an email based on a user input, but the user input is invalid or the email cannot be sent, you might not want to consider the flow run as successful. By using the ‘Terminate’ action with the status ‘Failed’, you can make sure that the flow run reflects the actual outcome of your flow.
For more information, you could check out these resources:
Terminate Control : Power Automate/Flow https://powerusers.microsoft.com/t5/Power-Automate-Community-Blog/Terminate-Control-Power-Automate-Flow/ba-p/450165 : A blog post that explains how to use the ‘Terminate’ action with different status options and provides examples and screenshots.
Power Automate Actions – Terminate (Stop Flows During a Run) https://www.flowjoe.io/2022/03/15/power-automate-actions-terminate-stop-flows-during-a-run/ : A video tutorial that shows how to use the ‘Terminate’ action with different status options and provides examples and demonstrations.
There is a system table called Flow Runs that contains the details of any run and that can be used for creating alerts.