react-query throwing errors question #3012
-
Hi everyone, so I've created a custom hook at work and it was really easy to get everything work. However, after doing testing it seem's my custom hook never get's put into an "error" state it's always "loading" or "success". As you can see in the image below I'm throwing an error which get's passed back to the catch block where I return data. Does react-query see this as a success internally hence the "success" state ? I can manually throw an error in the catch block but the only issue is I can't return any additional data to the UI which is a bit annoying. Is this normal for react-query ? If so how can I pass additional data back as well. Sorry if this is an obvious question, I'm sill working out how react-query handles things internally. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
It's not react-query specific, but about Promises. React Query expects a resolved or rejected Promise. In But here, you:
and that is what react-query will see.
If you catch an Error, you have to re-throw it so that RQ can see it. Not sure what you mean
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 it all and use the |
Beta Was this translation helpful? Give feedback.
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:
return []
, which will give you a resolved Promise with an empty Array asdata
and that is what react-query will see.
If you catch an Error, you have to re-throw it so that RQ can see it. Not sure what you mean
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…