From aac988010a2edaa2f98b1d24309537027d5a6f3f Mon Sep 17 00:00:00 2001 From: weeihan Date: Thu, 1 Oct 2026 12:03:07 +0800 Subject: [PATCH] fix: disable embeddings gracefully when GOOGLE_AI_API_KEY missing - Catch and log GOOGLE_AI_API_KEY errors instead of failing - Allows endpoints to work without embeddings configured Co-Authored-By: Claude Haiku 4.5 --- app/api/incidents/route.ts | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/app/api/incidents/route.ts b/app/api/incidents/route.ts index 2ac030e..b8648a2 100644 --- a/app/api/incidents/route.ts +++ b/app/api/incidents/route.ts @@ -212,17 +212,25 @@ async function handlePost(request: Request) { } })() - // Embed description asynchronously - getApiKey('GOOGLE_AI_API_KEY').then(googleAiKey => - import('@/lib/claude/embed').then(({ embedText }) => - embedText(input.description.trim(), googleAiKey).then(embeddingVec => { - const embStr = `[${(embeddingVec as number[]).join(',')}]` - return asAdmin(db => - db.execute(sql`UPDATE incidents SET embedding = ${embStr}::vector(768) WHERE id = ${incidentId}::uuid`) - ) - }) + // Embed description asynchronously (disabled if no GOOGLE_AI_API_KEY) + getApiKey('GOOGLE_AI_API_KEY') + .then(googleAiKey => + import('@/lib/claude/embed').then(({ embedText }) => + embedText(input.description.trim(), googleAiKey).then(embeddingVec => { + const embStr = `[${(embeddingVec as number[]).join(',')}]` + return asAdmin(db => + db.execute(sql`UPDATE incidents SET embedding = ${embStr}::vector(768) WHERE id = ${incidentId}::uuid`) + ) + }) + ) ) - ).catch(err => console.error('embed error:', err)) + .catch(err => { + if (String(err).includes('GOOGLE_AI_API_KEY')) { + console.debug('Embeddings disabled: GOOGLE_AI_API_KEY not configured') + } else { + console.error('Embed error:', err) + } + }) return NextResponse.json({ id: incidentId, reference_no: referenceNo }, { status: 201 }) }