From c2f41b20a7ccc223e8ab56855e65e7e50fd88c9e Mon Sep 17 00:00:00 2001 From: Andrew Jiang Date: Wed, 5 Mar 2025 17:37:33 -0500 Subject: [PATCH] fix: add some failsafes to the algolia reindexer (#2250) --- .../fern-docs/search/v2/reindex/algolia/route.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/fern-docs/bundle/src/app/api/fern-docs/search/v2/reindex/algolia/route.ts b/packages/fern-docs/bundle/src/app/api/fern-docs/search/v2/reindex/algolia/route.ts index d8d28a0d74..ec3582674d 100644 --- a/packages/fern-docs/bundle/src/app/api/fern-docs/search/v2/reindex/algolia/route.ts +++ b/packages/fern-docs/bundle/src/app/api/fern-docs/search/v2/reindex/algolia/route.ts @@ -24,13 +24,22 @@ export async function GET(req: NextRequest): Promise { const domain = getDocsDomainEdge(req); try { + console.debug("Reindex algolia for domain:", domain); const orgMetadata = await getOrgMetadataForDomain(withoutStaging(domain)); + // note: org-for-metadata is not always available, so we'll just continue to reindex assuming the domain is production + // if (orgMetadata == null) { + // return NextResponse.json("Not found", { status: 404 }); + // } + if (orgMetadata == null) { - return NextResponse.json("Not found", { status: 404 }); + console.debug( + "getOrgMetadataForDomain failed. Assuming domain is production" + ); } // If the domain is a preview URL, we don't want to reindex - if (orgMetadata.isPreviewUrl) { + if (orgMetadata?.isPreviewUrl) { + console.debug("Domain is a preview URL, skipping reindex"); return NextResponse.json({ added: 0, updated: 0, @@ -38,7 +47,6 @@ export async function GET(req: NextRequest): Promise { unindexable: 0, }); } - const start = Date.now(); const [authEdgeConfig, edgeFlags] = await Promise.all([ getAuthEdgeConfig(domain),