Skip to content

Commit ee6e2d8

Browse files
authored
fix(vectorize): return undefined instead of throwing in dev with no remote (#399)
1 parent 572f205 commit ee6e2d8

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

playground/server/api/vectorize/index.get.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ export default eventHandler(async (event) => {
22
const { query } = await getValidatedQuery(event, z.object({
33
query: z.array(z.number())
44
}).parse)
5-
const index = hubVectorize('example')
6-
return index.query(query)
5+
return hubVectorize('example')?.query(query) || []
76
})

src/runtime/vectorize/server/utils/vectorize.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type VectorizeIndexes = keyof RuntimeConfig['hub']['vectorize'] & string
3030
*
3131
* @see https://hub.nuxt.com/docs/features/vectorize
3232
*/
33-
export function hubVectorize(index: VectorizeIndexes): Vectorize {
33+
export function hubVectorize(index: VectorizeIndexes): Vectorize | undefined {
3434
requireNuxtHubFeature('vectorize')
3535

3636
if (_vectorize[index]) {
@@ -52,10 +52,7 @@ export function hubVectorize(index: VectorizeIndexes): Vectorize {
5252
return _vectorize[index]
5353
}
5454
if (import.meta.dev && !hub.remote) {
55-
throw createError({
56-
statusCode: 500,
57-
message: 'hubVectorize() is only supported with remote storage in development mode'
58-
})
55+
return undefined
5956
}
6057

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

0 commit comments

Comments
 (0)