Error Logging onto Retool Database

I'm trying to configure error logging for an app.

How would I save all page errors that pop-up on page onto a retool database table?

I've done something similar for individual query failures like below, but I need to capture all errors that pop-up on page.

1 Like

Hello @adrquint ,

I understand your issue and here’s how to set up a dynamic JavaScript query and corresponding SQL query for logging error messages into your database for each query failure in Retool.

Step 1: Set Up the Database Table

Make sure your database has a table to store the error logs. Here's an example schema for the error_logs table:

CREATE TABLE error_logs (
  id SERIAL PRIMARY KEY,
  user_email TEXT,
  query_name TEXT,
  error_message TEXT,
  timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Step 2: Create a SQL Query for Logging

  1. Add a new SQL Query in Retool and name it logErrorQuery.
  2. Use the following SQL for the query:
INSERT INTO
  error_logs (user_email, query_name, error_message)
VALUES
  ({{ user_email }}, {{ query_name }}, {{ error_message }});

Dynamic Variables:

  • user_email: Fetched dynamically from the current_user object.
  • query_name: Name of the failing query.
  • error_message: The error message from the query failure.

Step 3: Attach Error Handling to Queries

For each query in your app, use the onFailure handler to call the logError query

I give you scrrenshots for more understand.
image

3 Likes

Hi @adrquint,

Just wanted to circle back and confirm that @WidleStudioLLP's response works for your use case!

1 Like