diff --git a/src/components/LoadingWrapper.tsx b/src/components/LoadingWrapper.tsx index 36f909c..af19857 100644 --- a/src/components/LoadingWrapper.tsx +++ b/src/components/LoadingWrapper.tsx @@ -1,31 +1,38 @@ import { type UseTRPCQueryResult } from "@trpc/react-query/shared"; import { LoadingBarChart } from "./LoadingBarChart"; import { ErrorNotice } from "./notice"; +import { type TRPCClientErrorLike } from "@trpc/client"; +import { type TRPCErrorShape } from "@trpc/server/rpc"; +import { type AnyProcedure, type AnyRouter } from "@trpc/server"; /** * Generic query wrapper which handles the states of a query * (loading, error, etc.). Will hydrate child with query.data * */ -export function QueryWaitWrapper({ +export function QueryWaitWrapper< + TData, + TRouterOrProcedure extends AnyProcedure | AnyRouter | TRPCErrorShape +>({ query, Render, }: { - query: UseTRPCQueryResult; + query: UseTRPCQueryResult>; Render: (data: TData) => JSX.Element; }) { if (query.isLoading) { return ; } - console.log(query.data); - if (!query.data || query.isError) { return (
diff --git a/src/pages/resources/[id]/edit.tsx b/src/pages/resources/[id]/edit.tsx index 82b1634..a5d33c2 100644 --- a/src/pages/resources/[id]/edit.tsx +++ b/src/pages/resources/[id]/edit.tsx @@ -22,9 +22,8 @@ const EditResourcePage = () => { { id }, { enabled: router.isReady, - onError(err) { - console.log(err); - throw err; + retry(_failureCount, error) { + return error.data?.httpStatus !== 404; }, } ); diff --git a/src/pages/resources/[id]/index.tsx b/src/pages/resources/[id]/index.tsx index 837dea4..b4471ba 100644 --- a/src/pages/resources/[id]/index.tsx +++ b/src/pages/resources/[id]/index.tsx @@ -82,7 +82,14 @@ const ResourceViewPage = () => { const router = useRouter(); const id = router.query["id"]?.toString() ?? ""; - const resourceQuery = api.auditoryResource.byId.useQuery({ id }); + const resourceQuery = api.auditoryResource.byId.useQuery( + { id }, + { + retry(_failureCount, error) { + return error.data?.httpStatus !== 404; + }, + } + ); const ConditionalView = (data: AuditoryResource) => { return (