How do I reference a query's error inside of the query's failure handler without causing a dependency cycle?

I'm trying to handle when a particular REST API query responds with a 401 status code. This indicates that the access token I am passing along is expired. In this case, I want to refresh the token and then retry the query. In order to do this, I created a failure handler in that query that "Only run[s] when" {{ !!query.error && query.error.statusCode == 401 }}. This seems to behave exactly like I want it to but Retool complains that it detected a dependency cycle and notifies me of this every time I load the app.

Is there something wrong with the approach I am taking? If not, is there a way to not have Retool show this dependency cycle error every time on app load?

You might want to add that as a Failure in the Event Handler in the General tab instead. I have implemented something similar because I needed to handle a 403 for a specific and good reason based on an algorithm.
So, for example, if I received a 403, it was a failure but I handled that failuer in that wuery under the General tab as a Failure event.

Yep, thats where I have the failure handler set up


For reference, this is what the dependency cycle notifications look like. There's a few instances of similar queries which why there are multiple error notifications.

That's the problem I think it looks like you're setting the failure to be true inside of the failure event - use one ! instead of two and see what happens

Am I misunderstanding what the "Only run when" field is supposed to do?

{{ !!query?.error && query.error.statusCode == 401 }} <- this is saying: if query has an error and the error's statusCode is 401. Putting this in the "Only run when" field should mean that this failure handler only runs when there is an error with statusCode 401 right?

ah figured it out. for future reference, you need to use self instead of the query name. something like {{ !!self?.error && self.error.statusCode == 401 }}

1 Like

OK I think the problem is the error.statusCode with the query

What I have done is set up a query to look at
{{self.data.metadata.status == '409'}} in your case it's a 401 (but you should check to make sure that is the code coming back.. I enter this in the "Only run when" field.

I have this logic set up as a Failure event handler and if I get back the status 409, I run another query...