There are plenty of error handling blog’s out there for Power Automate. Microsoft event has one https://flow.microsoft.com/en-us/blog/error-handling/.
However, I’ve always struggled with getting the actual error message. These blogs usually show how to catch an error, but they never seem to show how to log the error. In a typical error handling situation, I am catching the error then I am logging the error to either a database, a SharePoint list, or even an email so we can troubleshoot.
In the below example you will see a simple HTTP Flow (FYI: type of flow doesn’t matter for the purposes of this blog). With an HTTP Flow, we typically want to return either a Success Response or a Failure Response. And, of course, if we return a Failure Response, we want to give the real error message in the Body.
In the above Flow, we have an opportunity for an error in the Compose action. Particularly around the “formatDateTime”. In the example above, there is a chance the date time is invalid and won’t get formatted. That is one of our “known” issues. But, there might be other “unknown” issues. Thus, we don’t want to assume anything and we want to return the real error in the Failure Response (i.e.: Status Code 400).
So, how is this accomplished:
- Wrap the Actions in a Scope – note: wrap all your actions in a scope (or, at least any action that can possibly produce an error)
- Add a Parallel action at the end and configure the run after for failed and timed out
- Use the expression result(‘Scope’) to get the error message from your scope above
That’s it. The trick all along was to wrap in a scope and use result(‘Scope’). Now you get real error messages!
Leave A Comment