Skip to content

Commit

Permalink
fix(vectorize): return undefined instead of throwing in dev with no…
Browse files Browse the repository at this point in the history
… remote (#399)
  • Loading branch information
atinux authored Dec 17, 2024
1 parent 572f205 commit ee6e2d8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
3 changes: 1 addition & 2 deletions playground/server/api/vectorize/index.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ export default eventHandler(async (event) => {
const { query } = await getValidatedQuery(event, z.object({
query: z.array(z.number())
}).parse)
const index = hubVectorize('example')
return index.query(query)
return hubVectorize('example')?.query(query) || []
})
7 changes: 2 additions & 5 deletions src/runtime/vectorize/server/utils/vectorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type VectorizeIndexes = keyof RuntimeConfig['hub']['vectorize'] & string
*
* @see https://hub.nuxt.com/docs/features/vectorize
*/
export function hubVectorize(index: VectorizeIndexes): Vectorize {
export function hubVectorize(index: VectorizeIndexes): Vectorize | undefined {
requireNuxtHubFeature('vectorize')

if (_vectorize[index]) {
Expand All @@ -52,10 +52,7 @@ export function hubVectorize(index: VectorizeIndexes): Vectorize {
return _vectorize[index]
}
if (import.meta.dev && !hub.remote) {
throw createError({
statusCode: 500,
message: 'hubVectorize() is only supported with remote storage in development mode'
})
return undefined
}

throw createError(`Missing Cloudflare Vectorize binding (${bindingName})`)
Expand Down

0 comments on commit ee6e2d8

Please sign in to comment.