Introduction
A few weeks ago, my good friend Josh Cook wrote a blog post for Power Automate about getting the error message when implementing the try/catch pattern with a Flow. We discussed if this could be used with Logic Apps, and Josh confirmed that it could, even though the Logic App documentation doesn’t cover it very well. Josh’s original Flow post is- Grabbing an error message from a failed run.
Following this great find, I wanted to check if we could then send the error message to Turbo360 BAM so I can access it for troubleshooting.
In my Logic App below, I have implemented the try-catch pattern where the catch scope only executes if the try scope fails.
Inside the catch scope, I have a BAM Checkpoint action to tell Turbo360 that my BAM milestone failed. Before I call the checkpoint, I need to format my error message as Logic Apps will give me quite a detailed error message, and I only want certain information to be sent to BAM. To do this, we will first parse the result message from the try scope just like Josh did in his Flow post.
The result expression we used as the input is shown below
In this article, I did want to make one slight change to what Josh does in his Flow post. When I have the result from the try scope, it also included all of the skipped shapes, which might end up with a bunch of noise in a big error message, so I wanted to filter the error message, so I push to BAM the necessary info about what failed. In the below Filter shape, I can filter the array to get only actions which failed.
Next, I am going to use the Select shape as Josh did, but as I only now have the failed actions, I found that some steps may have slightly different info depending on what the action does, so I am going to take the entire action output to use as the error message.
I think this bit may vary on what is best on a per Logic App basis but try it out and see what works best for you.
How Turbo360 BAM helps in Logic App Error Handling?
I can now pass the output from the select shape to the exception property on the BAM checkpoint call, which will push my error message to BAM.
The contents of the catch block look like the below:
When I run my Logic App now and an error, this catch block will kick in, and I will send the error info to BAM.
When I look at my BAM tracking data in Turbo360 I can then see that my BAM transaction failed at the Batch Complete stage.
When I click on the stage that got the error, I can now see the error message passed to BAM from the Logic App.
In this case, you can see I have the output message from the Logic App Http shape that failed, and I have the headers and the body with the invalid key error message. I am sure there is more I can do to tidy up the error message if I wanted.
Wrap Up
Hopefully, this little walkthrough will show you how the excellent find from Josh can also help us in Logic Apps and send errors to Business Activity Monitoring in Turbo360 to make it easier to support troubleshooting our Logic App solutions.
You can also take a look at our pillar page dedicated to Distributed tracing to get better insights on the topic.