Skip to content
Discussion options

You must be logged in to vote

It's not react-query specific, but about Promises. React Query expects a resolved or rejected Promise. In async functions, thrown Errors get transformed to a failed Promise.

But here, you:

  • throw an Error
  • catch it
  • return [], which will give you a resolved Promise with an empty Array as data

and that is what react-query will see.

I can manually throw an error in the catch block

If you catch an Error, you have to re-throw it so that RQ can see it. Not sure what you mean

but the only issue is I can't return any additional data to the UI which is a bit annoying.

not sure what you mean by that at all.


if you only catch the error because you want to log it, it would be better to not catch…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@AlexMachin1997
Comment options

@TkDodo
Comment options

@AlexMachin1997
Comment options

Answer selected by AlexMachin1997
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants