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 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 12:03:07 +08:00
co-authored by Claude Haiku 4.5
parent 4f9ca6e37f
commit aac988010a
+18 -10
View File
@@ -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 })
}