T
TanStack•3y ago
exotic-emerald

Is error resolved with `onError` callback?

Hello Is the error resolved on the onError callback or do I need to await and parse it?
onError: async (error: Response) => {
const response = await error.json();
logErrorToSentry(response);
},
onError: async (error: Response) => {
const response = await error.json();
logErrorToSentry(response);
},
or like this
onError: async (error: Response) => {
logErrorToSentry(error);
},
onError: async (error: Response) => {
logErrorToSentry(error);
},
2 Replies
exotic-emerald
exotic-emerald•3y ago
I think it depends what your query function is throwing, which I can't see above. You can throw anything which RQ will catch for the onError callback. For instance, if your query function used axios, then you should have error as an AxiosError. TkDodo wrote an answer to this on SO with extra detail which might give you more clarity: https://stackoverflow.com/a/72373622
Stack Overflow
What's the type of React Query's Error and how to handle different ...
I'm using React Query with typescript to fetch data in my project and I'm trying to use the error the useQuery hook returns to display a message describing the error if it exists like this : {isErr...
foreign-sapphire
foreign-sapphire•3y ago
The error is the rejected/thrown value from the query/mutation function. You shouldn't need to do anything to read it in the error callback 🙂

Did you find this page helpful?