T
TanStack16mo ago
noble-gold

When throwOnError is false how does react-query not throw an error the first time but store in error

const { data, refetch, isSuccess, isError } = useQuery({
queryKey: ['test'],
queryFn: async () => {
throw new Error('test');
},
retry: false,
throwOnError: false,
});
const { data, refetch, isSuccess, isError } = useQuery({
queryKey: ['test'],
queryFn: async () => {
throw new Error('test');
},
retry: false,
throwOnError: false,
});
Assuming this is a query requesting user information, I don't want to throw an error to the outside world when a 401 error occurs. queryFn In a real world situation I would use trpc, currently it is assumed. I don't want to use ErrorBoundary here, which would cause the UI to fall back in a way that doesn't fit my business logic.
1 Reply
noble-gold
noble-goldOP16mo ago
When retry is closed, it always throws an error seems to ignore the configuration about throwOnError?

Did you find this page helpful?