Track Query Errors on Prefetch phase #3306
Replies: 3 comments 2 replies
-
It would be great if we can add |
Beta Was this translation helpful? Give feedback.
-
you can just do In fact, It's also in the docs on the page you linked:
|
Beta Was this translation helpful? Give feedback.
-
export const getServerSideProps: GetServerSideProps = async (ctx) => {
const { bid } = ctx.query;
await Promise.all([
queryClient.prefetchQuery(["book", { bookId: bid as string }], () =>
getBook(parseInt(bid as string), ctx)
),
queryClient.prefetchInfiniteQuery(
["announcements"],
({ pageParam = 1 }) => getAnnouncements({ page: pageParam }, ctx)
),
queryClient.prefetchQuery(["me"], () => getUser(ctx)),
]);
return {
props: {
dehydratedState: JSON.parse(JSON.stringify(dehydrate(queryClient))),
},
};
}; This is my prefetch code in NextJS SSR, I want to return 404 when the prefetchQuery has error. return {
notFound: true,
} Help me how I can catch the prefetchQuery error in NextJS SSR. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey @TkDodo, I'm looking for ways to track query errors on the prefetch phase.
Sometimes a prefetch call in getServerSideProps could go wrong, I would like to detect errors and redirect eventually.
Do you know if there's an existing way to do this?
As per the React-Qeury docs, I can read the following on the prefetchQuery section "A promise is returned that will either immediately resolve if no fetch is needed or after the query has been executed. It will not return any data or throw any errors."
How can we know if there was an error on the prefetch query phase?
Thanks
cc/ @tannerlinsley
Beta Was this translation helpful? Give feedback.
All reactions