Error management in Power Automate is of paramount importance to ensure the reliability and resilience of automated workflows. As processes become more intricate and involve multiple steps, the likelihood of encountering errors increases. Effective error handling mechanisms help identify, diagnose, and address issues promptly, preventing workflow interruptions and data inconsistencies.
Disclaimer:
This Article handles Information which can be used differently. Error managment can be different from Enterprise to Enterprise.
What is the Problem?
In process automation, having visibility into errors that occur during the execution of your workflow is critical. Unfortunately, Power Automate doesn’t provide an out-of-the-box, comprehensive error management solution to handle all potential errors that may arise. However, this presents an opportunity for us to be creative and come up with our own strategies for error handling. By being proactive and resourceful, we can implement effective error management techniques that ensure our workflows are robust and resilient, even in the face of unexpected errors.
One approach for error management in Power Automate involves using the „Parse JSON“ action to retrieve error messages. However, a challenge arises due to variations in JSON structures for each action and response.
What could be an alternative
Nothing. Because some Actions are „special“ we can’t simply use any methode for all of them But there is a way how you can deal with it
What can you do?
There are multiple ways to start manage errors. Every website has another way to deal with in and nearly all of the have their pros and cons.
On this tutorial/article it will not be different. We show you what we use to deal with errors during our Power Automate.
Error Handling
Step 1: Try-Catch-Finally
If you are familiar with progamming, you know, you should use a try block every time you need to catch an exception. Mostly used when calling another datasource or a function outside of your control.
We use Scope-Actions to simulate a Try-Catch Function.
- Create a Scope and name it „Try“.
Here you put all your automation in. - Create a Scope and call it „Catch“
- Edit the Run after configuration and set it to „has failed“ and „has timed out“
Here you put the Actions it should run through, if any Action in the „Try“ failed
- Edit the Run after configuration and set it to „has failed“ and „has timed out“
- Create a Scope and call it „Finally“
- Edit the Run after configurations and set it to „on success, is skipped“
Here you put Actions, which closes the automation Process
- Edit the Run after configurations and set it to „on success, is skipped“
The Catch
Filter Array
In the Scope Action you should now use the „Filter Array“ Option. As the from Property, we use the following expression:
result('Try')
This retrieves all Actions in the Scope and their status. To Filter an Action on their status „Failed“ or „TimedOut“, if you use an API which don’t answer, switch to the advanced mode in the Filter and input this value:
@or(equals(item()?['Status'], 'Failed'),equals(item()?['Status'], 'TimedOut'))
Condition
As I mentioned some of the Actions has their Error Messages inside an Error Header. For example SharePoint hasn’t an error property. Instead their error message is simply build inside the body property as message.
So if you use one of those action, look at this table and set the condition:
Connector | Condition | Equals |
SharePoint | @{first(body(‚Filter_array‘))?[‚inputs‘]?[‚host‘]?[‚connectionReferenceName‘]} | shared_sharepointonline |
Excel Online | @{first(body(‚Filter_array‘))?[‚inputs‘]?[‚host‘]?[‚connectionReferenceName‘]} | shared_excelonlinebusiness |
Grab Error message
As its today you can grab the most error messages with item()?[‚body‘]?[‚message‘] No need of the [‚error‘].
Please replace item() with first(body(‚%ACTION%)…) if you don’t use it in a Data Operation
To grab the error you need to refere to the following:
- If it is one of the special Actions
- first(body(‚Filter_array‘))?[‚body‘]?[‚message‘]
- For any other Action
- first(body(‚Filter_array‘))?[‚body‘]?[‚error‘]?[‚message‘]
Now that you have captured the error, it’s time to make a decision on how to proceed. You have two options: you can either send yourself an email notification or update a database with the relevant information. Choose the approach that best suits your workflow and enables you to effectively manage errors and take appropriate actions. With this flexibility, you can ensure smoother and more efficient handling of errors in your Power Automate process.