When manually triggering a query from a script, if the query times out, Retool does not throw an error. Instead it "successfully" returns a value of "undefined".
See the sample code below. Assume query1 has a timeout of 1s and it reaches out to an endpoint which has a delay of 2s, meaning the query should always hit a network timeout.
(async () => {
try {
// Assume the following query fails with a network timeout
const res = await query1.trigger();
// Logic continues here, but should have gone into the catch block
} catch (err) {
// Logic does NOT make it here even though the query failed
}
})();
// same thing for...
query1.trigger()
.then(res => { // Logic goes here })
.catch(err => { // Does NOT make it here })
The catch block is never hit, even though query1 technically failed.
Is this a limitation of the trigger() method? Does it not see network failures as errors?
Wrapping the trigger() method in a promise and using the onSuccess/onFailure callbacks works:
(async () => {
try {
const res = await test();
} catch (err) {
// Logic correctly makes it here
}
})();
function test() {
return new Promise((resolve, reject) => {
query1.trigger({
onSuccess: (res) => resolve(res),
onFailure: (err) => reject(err)
});
});
}