Failure in Rest API triggering Success Event Handlers


I've built a button that takes data from the selected row in a table and sends it to our production database via a Rest API. This works fine for most cases, but the lingering issue is that when the API fails, retool understands it instead as a success.

This is a challenge because I want to run user notifications and other actions upon failures, and different ones upon success.

In this screenshots we can see the API response comes back with an error:

In this screenshot we can see retool interprets this action as a success:

So the question is:
How can I interpret API failures as failures in retool rather than successes?

Thanks for the help :slight_smile:

I think if the API isnt throwing any Error, retool will interpret it as success even if the response of the API is a message with the error details

The API is an internally built solution, so I can modify it. What do I need to do to get retool to understand it as a failure rather than a success in the response?

Hi there,

Happy to help out here and for this to work, you will want to configure your Rest API to return a status code to communicate if it was a success (200, etc.) or failure (400, etc.).

You can refer to this article here for API response codes to return depending on the outcome.

Retool will recognize these codes and respond accordingly.

Hope this helps and let me know if you have any additional questions!