How to handle errors in Power Automate (2024)

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.

How to handle errors in Power Automate (1)

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:

How to handle errors in Power Automate (2)

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.

How to handle errors in Power Automate (3)

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

How to handle errors in Power Automate (4)

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.

How to handle errors in Power Automate (5)

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

How to handle errors in Power Automate (6)

This is how the flow run looks when it fails:

How to handle errors in Power Automate (7)

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!

How to handle errors in Power Automate (8)

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.

How to handle errors in Power Automate (9)

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:

How to handle errors in Power Automate (10)
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>
How to handle errors in Power Automate (11)

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.

How to handle errors in Power Automate (12)

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:

How to handle errors in Power Automate (13)

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

How to handle errors in Power Automate (14)

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:

How to handle errors in Power Automate (15)

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.

How to handle errors in Power Automate (2024)

References

Top Articles
Latest Posts
Article information

Author: Nathanial Hackett

Last Updated:

Views: 5654

Rating: 4.1 / 5 (52 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Nathanial Hackett

Birthday: 1997-10-09

Address: Apt. 935 264 Abshire Canyon, South Nerissachester, NM 01800

Phone: +9752624861224

Job: Forward Technology Assistant

Hobby: Listening to music, Shopping, Vacation, Baton twirling, Flower arranging, Blacksmithing, Do it yourself

Introduction: My name is Nathanial Hackett, I am a lovely, curious, smiling, lively, thoughtful, courageous, lively person who loves writing and wants to share my knowledge and understanding with you.