Make your js query fail and trigger calling onFailure()

If I want one of my js queries to fail, how do I properly go about that? If I trigger the query from another query and some failure condition exists, I want onFailure(error) called.

If I throw an error it works, sort of: throw new Error('Whoops!')

But I cannot get the error message returned. I get a basically empty Error object. I would like to just send back something like:

{success: false, error: "You forgot something nimrod!"}

I tried various ways of calling Promise.reject() assuming that the whole query was somehow wrapped in a promise, but either I assume wrong or I don't know how to do it.

Hey Bradly!

Yeah it doesn't look like we surface the thrown error anywhere inside of the JS query, like we do for other resource types. This would be a good bit of data for us to add.

In the meantime, the best workaround I can think of would be doing a tempState.setValue() with the content of the error that you are about to throw? That way at least it would be accessible somewhere inside of the data model!

Could you share your query set up?

I was just playing with the idea in case it did come up and I saw nothing in the docs on it, so nothing to share yet!

This is mostly resolved by @church over here: How to force javascript query to fail?