NetFlows

Power Automate: Best Practices for Error Handling

Power Automate is a cloud-based solution for automating business processes. With so-called flows, recurring tasks can typically be automated without programming knowledge – from structured data collection and document creation to seamless synchronization between software applications.

However, for these automations to work reliably, careful planning and monitoring are required. A flow can fail due to unexpected errors – whether it’s due to the input of unforeseen data formats or connection issues when communicating with API endpoints. The reasons for errors can be diverse and are not always foreseeable during development.

To prevent such errors from disrupting business operations, effective error handling is essential.

In this article, we will share proven best practices for error handling in Power Automate, helping you make your flows more robust.

Notification of failed flows

While we may not be able to avoid errors entirely, we at least want to be notified about them. Although Microsoft sends an email to the respective owners about failed flows by default, this is a summary notification that can often be delivered hours later. This is not sufficient for effective error handling.

A much better approach is to configure custom notifications that are sent immediately when an action within a flow fails.

Configure Run After

For this, we can use a setting available in every action of a flow: Configure Run After.

This allows us to specify the conditions under which an action will be executed. By default, an action only runs if the previous one has been successfully completed. However, this configuration can be adjusted so that an action – such as sending an email – is executed only if the previous action fails.

This setting can be configured in the Settings tab of the respective action.

Try and Catch

To avoid setting up individual error handling for each action, we can instead monitor an entire group of actions and receive a notification if any of these actions fail. In Power Automate, we can use the control element ‘Scope’ to group actions.

 

To test this, we will create a new flow and add a Scope-element with a single Compose-action. To deliberately cause the flow to fail, we will add an invalid expression (in this case, a division by zero) to the action.

 

We name this Scope-block ‘Try,’ following common practice, as it contains all the actions we ‘try’ to execute successfully.

Next, we add a second Scope-block, which will be executed after the Try-block. This block contains all the actions necessary for error handling. Following naming conventions, we call this block ‘Catch’ – as it ‘catches’ any errors from the Try-block if one occurs.

Now, we need to configure the settings of the Scope element to specify under which conditions the Catch-block will run (Configure Run After). In our case, it should only start if one of the actions in the Try-block fails.

 

Next, we add an action to the Catch-block that informs us about the failed flow – for example, by sending an email to a defined distribution list. This way, we will be immediately notified by email whenever the flow fails.

When we test the flow now, we receive an email notification. However, the flow will appear as ‘Succeeded’ in the execution history. This is because, technically, the flow was completed successfully – even though an error occurred.

To ensure the flow ends with a ‘Failed’ status, we add a ‘Terminate’ action, which will close the flow with the desired error status.

Enriching notifications with error details

A notification about a failed flow is useful, but it would be even better if the notification included details about the error that occurred.

With the function results(), we can generate an array that returns the status of all executed actions within a scope.

To achieve this, we add the Filter Array action to our Catch block and insert the following expression as the source (From):

results('Try')

We only want information about failed actions, so we add the following expression in the Filter field:

or(equals(item()?['Status'], 'Failed'),equals(item()?['Status'], 'TimedOut'))

This way, we get an array that contains only information about actions that either failed (‘Failed’) or exceeded the time limit (‘TimedOut’).

 

We can now process this filtered array into an HTML table, which we will later add to our notification. For this, we need the ‘Create HTML table’ action.

In our example, I define three columns there, whose values are dynamically filled from the filtered array.

 

We can now easily add the HTML table (output of the ‘Create HTML table’ action) to the body of our email.

To wrap up, it would be helpful if the notification included a link that takes us directly to the failed flow.

We can achieve this with an <a> tag and the following expression in the email body:

concat('https://make.powerautomate.com/environments/', workflow()?['tags']['environmentName'],'/flows/',workflow()?['name'],'/runs/',workflow()?['run']['name'])

Logging and analyzing errors

In addition to direct notifications about errors, it is important to log errors in a structured way. This allows patterns to be identified, root causes to be analyzed, and long-term improvements to be made to the flows.

A proven method is to store error details in a SharePoint list or a Dataverse table.

To achieve this, the Catch block can simply be extended with another action – for example, the ‘Create item’ action. Of course, a corresponding SharePoint list with relevant columns (timestamp, action, error message, etc.) must be created beforehand.

Conclusion

A thoughtful approach to error handling in Power Automate ensures that flows become more robust and fail-safe. Through targeted notifications, the provision of error details, and logging in SharePoint or Dataverse, issues can be quickly identified, analyzed, and resolved.

Microsoft Learn has a dedicated learning module on error handling.

NetFlows Logo