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

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