REST API Error Handling

Hi retool team - trying to figure out the best way to do error handling when using a REST API. The API I’m using is pretty simple and has an error response similar to Stripe.

If there is an error, the REST API will return a 400 and have an HTTP response body that looks like:

{
    "error": {
        "kind": "validation_error",
        "message": "Form cannot be Completed without an Index"
    }
}

If the query throws an error, I’d like to just return only the message to the user. I’ve tried enabling the Error Transformer and selecting the message (see image below).

This seems to actually work as when I preview the result in the query, it shows:

message: “Error transformer produced: Form cannot be Completed without an Index” - which is correct, however, when I actually run the query as part of the app function, the entire JSON response body is being shown, which is what I’m trying to avoid (see below).

Query Error (updateStatus): {“error”:{“kind”:“validation_error”,“message”:“Form cannot be Completed without an Index”}}

Am I missing something to plug this error transformer into the actual query error or something?

Thanks!

Dan

1 Like

Hey @gilcrest!

Thanks for reporting this, I see the same behavior on my end! I’m writing up a ticket to our engineering team to get this looked at. I couldn’t think of any workarounds other than displaying the message within a text component, but I wouldn’t recommend it as it’ll introduce unnecessary complexity.

I’ll update this thread once we have an update!

1 Like

Thanks! One other question I have while we’re at it :slightly_smiling_face:
If my API returns a 200 (OK), the Error transformer still seems to be executing? It seems like it executes no matter what is returned. In my case, the response body for a 200 is very different than the 400 error response and this is the error message I’m now receiving even though my API is responding successfully…

My assumption was that an Error Transformer would be something that is used to transform an error response only, but it appears that it is something that needs to handle whatever response may be sent (which I can understand after reading the Error transformer use cases you have for GraphQL). Is there an easy way to only fire this conditionally based on an HTTP 400 error? Or maybe I shouldn’t even be using an error transformer and should be using something else?

Thanks again!

Dan

Similar issue here but for me the notification always displays Query Error (QUERY_NAME_HERE): Query run error and nothing regarding my passed in message. Tested even with a simple return "error" but it displayed what was previously stated.

1 Like

I’m getting the same issue on my Retool pages. Whatever the API is responding, the Error Transformer doesn’t display the error property of my respond object… Any news on that?

Thanks.

1 Like

Not sure if something changed but my errors now show up as expected!

1 Like

Hey y’all! Good news — the bug has now been fixed! Rest error transformers will now return correct error messages :confetti_ball: Thank you to everyone for your feedback and patience here!

(And @mgmolisani-gamercraft thank you for being so quick to chime in, truly awesome to see :blush:)

My team is pretty happy they no longer have to follow my directions to open the console to see where I was temporarily logging the errors for them until this was resolved. The good news was it just started working no changes required.

So happy to hear it’s working, and so sorry to put you and your team through that. :sweat_smile:

This is great - I’m going to have to test it out ASAP (I had removed it). I wanted to ask a question about the intent of the error transformer. The tooltip for the transformer says the following:

Screen Shot 2020-10-23 at 8.26.13 PM

I didn’t read this carefully initially. Are error transformers really only for successful (200) query returns as it says in this tooltip? I’m trying to determine the best way to handle a 400 error that returns a different response body than if the query is successful.

Sorry to bug, but I’m still a bit confused - I’m gonna try it out now though!

Thanks!