import { useQuery } from "@tanstack/react-query"; import { z } from "zod"; import { ApiError } from "@/lib/api"; import { usePlatform } from "@/lib/platform"; export function useOptionalPrivateQuery(path: string, schema: z.ZodType, missingCode: string) { const { request, scope } = usePlatform(); return useQuery({ queryKey: ["private", scope, path], enabled: Boolean(scope), retry: false, queryFn: async ({ signal }) => { try { return await request(path, schema, { signal }); } catch (error) { if (error instanceof ApiError && error.status === 404 && error.code === missingCode) return null; throw error; } }, }); }