{"record":{"id":"276c69d358c845ba","repo":"payloadcms/payload","slug":"search-failed","errorCode":null,"errorMessage":"Search failed","messagePattern":"Search failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/ui/src/elements/Hierarchy/Search/useHierarchySearch.ts","lineNumber":92,"sourceCode":"              [titlePathField]: true,\n            },\n            where: {\n              [titleField]: { contains: query },\n            },\n          },\n          { addQueryPrefix: true },\n        )\n\n        const url = formatAdminURL({\n          apiRoute: api,\n          path: `/${collectionSlug}${queryString}`,\n          serverURL,\n        })\n\n        const response = await fetch(url, { credentials: 'include' })\n\n        if (!response.ok) {\n          throw new Error('Search failed')\n        }\n\n        const data = await response.json()\n        const docs: SearchResult[] = (data.docs || []).map((doc: Record<string, unknown>) => ({\n          ...doc,\n          path: doc[titlePathField] || '',\n        }))\n\n        setResults(append ? (prev) => [...prev, ...docs] : docs)\n        setHasNextPage(data.hasNextPage || false)\n        setTotalDocs(data.totalDocs || 0)\n        setPage(pageToFetch)\n        setCurrentQuery(query)\n      } catch {\n        if (!append) {\n          setResults([])\n          setHasNextPage(false)\n          setTotalDocs(0)","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/ui/src/elements/Hierarchy/Search/useHierarchySearch.ts#L74-L110","documentation":"A plain Error thrown in the Hierarchy field's client search hook (useHierarchySearch) when the admin API search fetch returns a non-ok response. The fetch targets the collection's list endpoint with a formatted admin URL and credentials included; any non-2xx aborts with this generic message.","triggerScenarios":"The hierarchy relationship search issues GET /<collectionSlug>?<query> and the server returns non-2xx: 401/403 (session expired), 404 (collection slug wrong), 500 (server-side query error), or a network failure.","commonSituations":"Admin session expired while the hierarchy panel is open; the target collection slug changed; a server-side error in the collection's find query (e.g. malformed where filter, DB issue); CORS/proxy stripping credentials.","solutions":["Check the network response status for the search GET to identify auth vs server error.","Re-authenticate if the response is 401/403 (session expired).","Verify the collectionSlug and query params produce a valid admin list URL.","Wrap the search call in a try/catch to degrade gracefully (show empty results / retry) instead of throwing."],"exampleFix":"// before\nconst response = await fetch(url, { credentials: 'include' })\nif (!response.ok) {\n  throw new Error('Search failed')\n}\n\n// after — graceful degradation with status\nconst response = await fetch(url, { credentials: 'include' })\nif (!response.ok) {\n  if (response.status === 401 || response.status === 403) {\n    setResults([])\n    return\n  }\n  throw new Error(`Search failed (${response.status})`)\n}","handlingStrategy":"try-catch","validationCode":"function buildHierarchySearchURL(args: { api: string; serverURL: string; collectionSlug: string; queryString: string }): string | null {\n  if (!args.collectionSlug) return null\n  return formatAdminURL({ apiRoute: args.api, path: `/${args.collectionSlug}${args.queryString}`, serverURL: args.serverURL })\n}\n\nconst url = buildHierarchySearchURL({ api, serverURL, collectionSlug, queryString })\nif (!url) throw new Error('Cannot search: missing collection slug')","typeGuard":"function isSearchFailure(err: unknown): err is Error {\n  return err instanceof Error && err.message === 'Search failed'\n}","tryCatchPattern":"try {\n  await runHierarchySearch(query)\n} catch (err) {\n  if (isSearchFailure(err)) {\n    setResults([]) // degrade gracefully\n    return\n  }\n  throw err\n}","preventionTips":["Include credentials on the search fetch so expired sessions are detectable.","Degrade to empty results instead of throwing when the search endpoint fails.","Re-fetch form state / re-auth on 401."],"tags":["ui","hierarchy","relationship","search","network","client"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}