Goal: I am calling one "Run JS Code" query from another "Run JS Code" query and would like to know if there was in error when calling the first query
I found this thread (How to force javascript query to fail? - #5 by bradlymathews) where another user near the end of the thread encounters the same issue, and the retool team responds in Jan 2023 saying this was fixed, but I still can't figure out how to propagate the error.
//barQuery "Run JS Code"
console.log("barQuery started")
let results = await fooQuery.trigger()
console.log("fooQuery results:")
console.log(results)
// results is undefined
// I would like to know whether the fooQuery call succeeded or not here
I think you can handle the errors directly in the Event Handlers of the JS Query and have it run a script/trigger what to do on an error. You can also just await the fooQuery.trigger and then use a ternary chain to return the data or error as needed:
ETA: I noticed an odd thing when switching between fooQuery return values... The first run of the barQuery script produced a null return but then subsequent calls worked as intended. This is probably a promise/async thing that I didn't resolve properly in hasty sample setup.
Thank you @pyrrho, what you suggested works (though interesting that it is a different pattern than triggering resource queries where the trigger() returns the actual result value)
Noticed this as well, but I can live with this.
The first run of the barQuery script produced a null return but then subsequent calls worked as intended.