- My goal: Update the UI with the error message returned from a query.
- Issue: The error property on a query doesn't appear to be populated synchronously.
- Steps I've taken to troubleshoot: Started by referencing this thread:
Error handling and queries - Additional info: (Cloud or Self-hosted, Screenshots) Cloud
I'm trying to do something that feels pretty normal for a UI/UX pattern, but Retool's query has some odd behavior regarding how it handles failures.
const body = {...}
const result = await someQuery.trigger({
additionalScope: {
body,
}
});
if (!result) {
console.error('Error: ', someQuery?.error)
someErrorText.setValue(someQuery?.error);
return;
}
utils.confetti();
return result;
A query will always return (assuming the syntax of the overall JS is correct and the query exist), but the result
won't be populated if there was a failure. In the above code, the if
block will execute reliably.
However, the error
property of someQuery
will not always populate. Typically, on encountering an error from the query on the first attempt, it will never be populated, and UI can't be updated with it in the above way.
The prior thread on this topic suggested to use the checkbox for "Keep variable references inside the query in sync with your app". This doesn't seem to make a difference regarding this behavior, and based on the tooltip, "If this query calls setValue on a component, ensure that future references to the component have the updated value," there's no reason to believe it would impact query in a way to address this.
As the prior poster also noticed, even using something like setTimeout
, the property doesn't seem to populate. Oddly, if you hover over the query and use the tooltip it prompts, you can see that the error is populated. The prior thread seemed to indicate that this is all due to replacing the reference under the hood, so error is never populated on what the query sees during its execution.
What is the reliable way to access the error property? This makes UI concerns around displaying errors difficult to do in a predictable fashion.