Throw Error in Selector
I'm applying parser in my
select
function, bascially to ensure I have the correct data types from the server and transform the API response into an object that the type is defined by me.
I'm using zod to catch the errors and the parser function does throw error. Now, I would like to tell react query that there's something wrong when doing data transformation in select
function. But it does nothing.
How to let react query knows that something wrong is happening?
I want the react query treat the error just like any API call error (rejected). Thus triggerin global onError function.
OR
do you think it's not the correct place to put the parser? Do I have to use it in my API function, the query function?3 Replies
fair-rose•14mo ago
It should be in the API function
genetic-orange•14mo ago
throwing errors in the select function is supported and should put the observer into error state, but what you are trying to do should really go into the queryFn, not select
rising-crimsonOP•14mo ago
Thank you everyone for the advice!