How to set `.error` property of JavaScript queries?

Understanding how queries work in Retool is essential. In Retool, every query has two properties: .data and .error. Typically, when executing a JavaScript query, the returned value is assigned to .data. However, you might expect that a thrown error would be captured and assigned to .error. Surprisingly, running the following JavaScript query results in query.error === undefined:

throw new Error("error message");

Even trying an alternative approach, such as the one shown below, still leaves .error undefined:

throw "error message";

This raises the question: Is there a way to explicitly set the value of .error in a JavaScript query?

I would appreciate any insights or suggestions on how to handle this scenario effectively. Thank you!

2 Likes

Hi @yuku,

This is a bug where error isn't getting updated properly :disappointed: I don't have a timeline for when this will be ready, but I can continue to keep you updated when it's available!

1 Like

Any updates on this? I just ran into the same situation where I'd like to control further processing based on whether a js query failed...

No updates yet :disappointed:, but I added your +1 to the internal request

@Tess
Any update here?
Error handlers are a pretty fundamental part of tools that your customers build.

Unfortunately, not yet :disappointed: I'll keep this thread posted when I get updates!

1 Like

I would like to +1 this please.

+1

Any updates in this topic?? @Tess

No updates to share yet :disappointed:

@Tess
+1

@Tess are there any updates on this, or at least when there'll be some investigation done into it? It's making debugging of longer queries really painful.

Hi there! I bumped the ticket internally. Hopefully, I'll have an update soon :crossed_fingers: Unfortunately, I'm not able to provide an eta for a fix yet :disappointed:

You can return error statements from query blocks, like so:

> if (errorCondition1) {
> return {error: 'error1'}
> }
> else if (validCondition) {
>//do some code
> return dataValue
> }
> else {
> return {error: 'unknownError'}
> }

In responses, you can add failure conditions. Example;
condition: {{ data.error == "error1" }} data.error.message: {{ "Error occurred: 1" }}

This works in the application builder. You can also build your own "error handling" logic.

Edit: previously posted about using return values. This does not work correctly. Capturing error values like this does.

You can now set the .error property of a JS query: