diff --git a/packages/web/components/templates/library/LibraryContainer.tsx b/packages/web/components/templates/library/LibraryContainer.tsx index 2a1d72441..6bb4829bd 100644 --- a/packages/web/components/templates/library/LibraryContainer.tsx +++ b/packages/web/components/templates/library/LibraryContainer.tsx @@ -164,6 +164,9 @@ export function LibraryContainer(props: LibraryContainerProps): JSX.Element { const items = itemsPages?.pages .flatMap((ad: LibraryItems) => { + if (!ad.edges) { + return [] + } return ad.edges.map((it) => ({ ...it, isLoading: it.node.state === 'PROCESSING', diff --git a/packages/web/lib/networking/library_items/useLibraryItems.tsx b/packages/web/lib/networking/library_items/useLibraryItems.tsx index 73899f857..c50f79eee 100644 --- a/packages/web/lib/networking/library_items/useLibraryItems.tsx +++ b/packages/web/lib/networking/library_items/useLibraryItems.tsx @@ -277,6 +277,9 @@ export function useGetLibraryItems( query: fullQuery, includeContent: false, })) as LibraryItemsData + if (response.search.errorCodes?.length) { + throw new Error(response.search.errorCodes[0]) + } let wasUnchanged = false if (cached && cached.pageParams.indexOf(pageParam) > -1) { const idx = cached.pageParams.indexOf(pageParam) @@ -326,8 +329,6 @@ export function useGetLibraryItems( return true }) ) - console.log('setting filteredPages: ', filteredPages) - return { ...data, pages: filteredPages, diff --git a/packages/web/pages/_error.tsx b/packages/web/pages/_error.tsx index 3331b2300..967af76a8 100644 --- a/packages/web/pages/_error.tsx +++ b/packages/web/pages/_error.tsx @@ -2,8 +2,16 @@ import NextErrorComponent from 'next/error' import * as Sentry from '@sentry/nextjs' +import { useEffect } from 'react' +import { useQueryClient } from '@tanstack/react-query' const MyError = ({ statusCode, hasGetInitialPropsRun, err }: any) => { + const queryClient = useQueryClient() + useEffect(() => { + console.log('unhandled exception occurred, clearing cached data.') + queryClient.clear() + }, []) + if (!hasGetInitialPropsRun && err) { // getInitialProps is not called in case of // https://github.com/vercel/next.js/issues/8592. As a workaround, we pass