web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Error Handling ClearCo...
Power Apps
Unanswered

Error Handling ClearConnect against a Power Automate Flow

(0) ShareShare
ReportReport
Posted on by 51

In Screen.OnVisible, I make a ClearConnect call against a Power Automate flow that is connected to my app, like:

 

ClearCollect(queryResults,'FlowName'.Run(parameter1));

 

which returns an array of JSON objects.  (As a result, the Flow's last step is a Response object rather than a Respond to a PowerApp object.)  The flow in turn queries other data sources and, as a result, the flow can fail.

 

If the flow fails for any reason, I want to notify the user, explain the type of error, and also make some changes to the appearance of the app, such disabling or hiding certain elements.

 

It's not clear how I can do this.  In the flow I can either return a success code (200 code) and an error message in the body or I can return a failure code (500) along with an error message, then the app can consume and display the message.  Returning 500 seems like a better approach.

 

When I return a 500 code along with a JSON object with an error message, this Error notification occurs:

 

FlowName.Run failed: { "error": { "code": 502, "source": "msmanaged-na.azure-apim.net", "clientRequestId": "xxxxxxxx-c58a-4cb0-b52e-f731c44386a6", "message": "BadGateway", "innerError": { "error": "Custom error message in flow." } } }

 

I did not build in this notification, the app is showing it on its own, I believe.

 

The app recognizes that an error occurred and does display the message returned from the flow along with other information.  But this is not user friendly or actionable.

 

How can I handle this error from a ClearCollect cleaning, make other changes to my app as a result and display the custom error message?

Categories:
I have the same question (0)
  • msalamonjl Profile Picture
    51 on at

    I may have partially solved this situation.

    First, I need to set up the Power Automate flow that returns the information to the PowerApp appropriately.  After each step in the flow where it can fail I add a parallel flow.  One side is taken if the prior step succeeds and the other side is taken if the prior step fails or times out.  For the success side, add the existing next steps from the flow that returns the array via a Response object. 

    For the failure side, add a Response object with an error status code (like 500).  And in the response body add an empty json object, like {}

     

    Then in the PowerApps code that called the Flow -- onVisible for the Screen:

    ClearCollect(queryResults,'FlowName'.Run(parameter1));

     

    I added this type of code:

     

    if(CountRows(queryResults) = 0, Notify("Error Message", Error,0));

     

    You can also add in a else clause that may do something like show the screen/input fields assuming they had previously been hidden.

     

    Although I have not tried this yet, to get custom error messages I could update the structure of the response from the flow to include an "error" or similar field and refresh the flow in PowerApps so that PowerApps is expecting an error field.   Then in the 500 Response object I can instead return something like:

    {"error":"custom error message"}

    In the success response the object would not contain "error".

     

    Then I could check to see if an error is returned -- I'm not sure the code below is correct:

     

    if(Not(IsBlank(First(queryResults).error)), Notify(First(queryResults).error, Error,0));

     

    Basically, check to see if the first record returned has an error message and, if so, display that error message.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 530

#2
WarrenBelz Profile Picture

WarrenBelz 459 Most Valuable Professional

#3
Haque Profile Picture

Haque 314

Last 30 days Overall leaderboard