In any application, error messages should be displayed if there are any failed actions. These message should be meaningful and must explain the issue and possible cause for these errors to users.
In this post, we will discuss how we can pass a custom error from Power Automate to a canvas app and display this message. Here is the output:
Let’s look at this example:
When we enter a file name, this app will get the last modified date/time for that file from SharePoint using Power Automate. As the button action, I am passing the FileName(TextInput1.Text) to a flow that will search for the file in Sharepoint location and get the last modified date/time of the file.
Set( flowres, GetLastModified.Run(TextInput1.Text); )
Importance of error handling in this app
In above example, if the file name is incorrect, the flow action will fail in Power Automate. This information should be given to users in an error message so that they will know that the flow failed and how to fix the issue.
Modifications to the flow to include error handling
- Initialize a string variable “ErrorMessage”
2. Add a parallel branch to the flow after SharePoint action. Configure run after setting and have branches execute per below
a. If the action is successful > update modified date variable with SharePoint file modified date
b. If the action failed/skipped/timed out > Update ErrorMessage variable with a custom error message
3. Configure run after setting to handle failed/skipped/timed out actions
4. Assign ErrorMessage variable to a field in “Respond to a PowerApp or flow” action. This will pass the error message to your canvas app
5. Go to canvas app and add the error message to a text label. We have assigned the flow output to “flowres” variable in the canvas app
6. Done ✅
7. Let’s test this by entering an incorrect file name. The flow should now pass our custom error message and display in canvas app.
This is just a sample. We can create multiple custom error variables and messages depending on the requirement. Thereafter, we can pass these values to Power Apps and display custom error messages appropriately.
In my next post, we will dive further into error handling in Power Automate + Power Apps.