A while back I write about a Try – Catch construction in Microsoft Flow. Within my Catch I then sent email with some limited information such as the title of the triggering item. This is of course great to identify the item causing the error but you might want more.
Then last week I wrote about Flow Analytics and finding your failed flow. Today I’m going to take this a bit further.
Something has gone wrong in my flow and I want to get the details within my flow:
So in this case I would like to include the status, message and source returned by my failing Get Item. I generated this error by trying to get item 0 from a list in SharePoint.
{ "status": 404, "message": "Item Not Found\r\nclientRequestId: ffe594bf-a0ee-49eb-8ec2-d5663c537fcd\r\nserviceRequestId: c7666e9e-5046-5000-bd79-d17875df57cb", "source": "https:/ /mytenant.sharepoint.com//_api/SP.APIHubConnector.GetListItem(listName='634dead0-b2c0-4a31-a11b-f548877c18ee',itemId='0')", "errors": [ "-1", "Microsoft.SharePoint.SPConnectorException" ] }
You could now set 3 variable with
body('Get_Item')?['Status'] body('Get_Item')?['Source'] body('Get_Item')?['Message']
How can we handle the flow failures while still keeping control over the flows.
I’m going to go back to my Try / catch post.
By moving my Set Variables into the Try / Catch we’re getting one step closer to where we want to be.
But now how do we handle a flow with many steps that could possible fail? We don’t just want to clutter the Scope – Catch action with a lot of actions collection the results form all potentially failing actions.
First after each potentially failing action I’m setting a variable body with the result of the action that I called. And within my Catch I’m setting the 3 variables So that I have the details of the failure.
One small problem through my catch will not happen anymore as my body is set successfully.
This is where we need to introduce the throw in flow. All I need to do is make something fail so that an error occurs and my catch will run. In my case I’m just setting an integer variable to a string value.
And now all I need to repeat is the Throw scope wherever I want to handle an error.
[…] There are different ways to implement this requirement, but you have to be very careful and to fully understand how error handling works in flow. I already discussed that in a previous post; you can also read Pieter Veenstra very good blog posts here and here. […]
this is a good post. however, I would like to group all my actions under one Scope – Try. If anything fails within that scope, how do I get the error message? In your example, you can get error by body(‘Get_Item’)?[‘Message’], but when you have multiple actions, how do you know which one failed?
You might want to have a look at the function library series that I wrote recently.
This includes a section about detailed error handling covering the problem you mentioned. Unfortunately there isn’t an errors function giving all errors during a flow.
https://veenstra.me.uk/2019/09/12/error-handling-with-function-libraries-in-microsoft-flow/