cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Banana
Level: Powered On

Error handling with Custom API

Hi - I'm investigating using custom API with PowerApps. However, it's not clear how one should handle errors returned by API.

 

For example, suppose I have a 400 response returned by API due to malformed user input that requires correction on user's part. 

 

When I try to run something that results in an error, from the user's POV, the button fades, then switches back on, with no other indication that something bad happened. If I switch to design view, I do see the yellow warning icon which only gives very generic "it returned a HTTP error".

 

I already tried using "Errors(MyCustomAPI)" or "Errors(MyTableAssignedByCustomAPI)" to collect the errors but neither are considered valid. 

 

So, how do I actually collect information on errors and handle this within PowerApps? Must I return some error information in a 200 response (which would break the REST model)?

1 ACCEPTED SOLUTION

Accepted Solutions
PowerApps Staff rgruian
PowerApps Staff

Re: Error handling with Custom API

In PowerApps, REST/server-specific error information (500, 404, etc) is not something that flows through the dataflow graph at runtime. The authoring environment "sees" these errors and shows icons/squiggles as you observed. However errors are not considered data, and as a result they cannot be manipulated via formulas. If you are hoping to get service-specific error codes and handle them via formulas, that is not possible in PowerApps today.

 

Failing operations will typically return blank responses. A quick way to see if an operation errored out is via the IsBlank function:

 

    If(IsBlank(yourRestCallHere), ... deal with failure ...)

 

If you absolutely need to "switch" on error codes, there are two avenues at the moment, but they require changes to your API:

 

1. Make the service stateful, and introduce a LastErrorCode function.

2. Make the service return the error code as data (e.g. response is an object, and the error is in one of the fields).

 

I hope this helps.

Radu Gruian [MSFT] ** PowerApps Staff

View solution in original post

3 REPLIES 3
PowerApps Staff rgruian
PowerApps Staff

Re: Error handling with Custom API

In PowerApps, REST/server-specific error information (500, 404, etc) is not something that flows through the dataflow graph at runtime. The authoring environment "sees" these errors and shows icons/squiggles as you observed. However errors are not considered data, and as a result they cannot be manipulated via formulas. If you are hoping to get service-specific error codes and handle them via formulas, that is not possible in PowerApps today.

 

Failing operations will typically return blank responses. A quick way to see if an operation errored out is via the IsBlank function:

 

    If(IsBlank(yourRestCallHere), ... deal with failure ...)

 

If you absolutely need to "switch" on error codes, there are two avenues at the moment, but they require changes to your API:

 

1. Make the service stateful, and introduce a LastErrorCode function.

2. Make the service return the error code as data (e.g. response is an object, and the error is in one of the fields).

 

I hope this helps.

Radu Gruian [MSFT] ** PowerApps Staff

View solution in original post

Banana
Level: Powered On

Re: Error handling with Custom API

Thank you for the clarification. For right now I'll adapt the 2nd suggestion (e.g. return error data as a field in the complex object.

 

Why? Because I don't want to have multiple API calls and because I haven't figured out how to gracefully handle asynchronous operation in PowerApps. In Javascript, we would define a callback function or use a Promise. In the context of a PowerApps formula, there is no such construct, unless maybe using a Timer control and testing for context variable being populated by the API but doing that for each API call can get onerous quickly. At the present, I usually assign the results into a context variable and use formula chaining which is not 100% perfect because of asynchronous nature. For example, a button would 1) execute an API call and 2) advance to next screen. But we of course don't want to advance to 2nd screen if there has been an error.

 

warren
Level: Powered On

Re: Error handling with Custom API

Hi @rgruian,

 

I am looking into something similar and stumbled across your response while searching a solution online. 

Similarly, i have implemented a custom connector, which gets triggered when i click on a button - triggered via the 'OnSelect' property.

 

What i would like to do, is to be able to inform user on the screen when an error has occurred during the connector's transaction. 

 

In my scenario, the connector's function is called 'PhotoToSp.PostPhoto' as shown below, which requires 5 arguments.

 

image.png

 

In your comment before, 

 

Failing operations will typically return blank responses. A quick way to see if an operation errored out is via the IsBlank function:

 

    If(IsBlank(yourRestCallHere), ... deal with failure ...)

 

I tried using IsBlank(PhotoToSP.PostPhoto..) for the conditioning, but it doesn't capture the error when it fails, or is it a syntax issue?

When you mention IsBlank(yourRestCallHere), is it the actual HTTP protocol that should be placed in the ()? If you can provide more details around this that would be great. Thanks!

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (4,656)