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 with Cu...
Power Apps
Answered

Error handling with Custom API

(0) ShareShare
ReportReport
Posted on by 18

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)?

Categories:
I have the same question (0)
  • Verified answer
    rgruian Profile Picture
    Microsoft Employee on at

    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.

  • Banana Profile Picture
    18 on at

    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 Profile Picture
    11 on at

    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!

  • CAC-93 Profile Picture
    82 on at

    Hello, 

    I would like to know if there has been an update to this response considering it is 8 years old. 

    Currently, I am sending POST requests through a custom connector to an Azure Function my team has built.

    We were planning on sending several reponses back:

     

    200 - for success

    400 - for an error in which the input was incomplete <--- this is the important one because we were hoping to use data that is returned by the Azure function in this scenario.

    500 - When an unexpected error occurs in the code

     

    What we planned on doing was, if the code returned a 400, we return JSON in the response body that would inform the user what information needs to be filled in. However, we have found that we cannot parse the response body when the response status is 400 (we can when the response status is 200, though) and therefore we cannot show the user a collection of "missing inputs" that they need to fill in. 

    This seems to be directly related to this post from EIGHT years ago. Has this situation changed? Is there any way to handle data from error Reponses? Is there a plan to parse data from error responses?

  • CAC-93 Profile Picture
    82 on at

    Furthermore, I do have a way to collect the errors returned from the custom connector (see attachment).

    Using this strategy, I am able to parse the JSON returned when an "error" response is returned from my custom connector. And, more importantly, I can take action based on what is returned in the error.

    It would be nice if Power Apps had a more direct approach for this.


    P.S. This was hastily put together. I should add extra validation that checks if "tempErrors" is empty or not to decide to take action. Otherwise, I could proceed with response from the custom connector directly (maybe by setting it to a contextual variable)...............the main point of this is to show one method to use where you can see the response body returned by an HTTP Response with a 400s or 500s status.

     

    CAC93_0-1706285594214.png

     

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 April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 846

#2
Valantis Profile Picture

Valantis 532

#3
Haque Profile Picture

Haque 410

Last 30 days Overall leaderboard