File tree 3 files changed +53
-7
lines changed
3 files changed +53
-7
lines changed Original file line number Diff line number Diff line change @@ -120,6 +120,38 @@ export const test_vector_search_vector_insert = {
120
120
} ,
121
121
} ;
122
122
123
+ export const test_vector_search_vector_insert_error = {
124
+ /**
125
+ * @param {unknown } ctr
126
+ * @param {Env } env
127
+ */
128
+ async test ( ctr , env ) {
129
+ const IDX = env [ "vector-search" ] ;
130
+ {
131
+ /** @type {Array<VectorizeVector> } */
132
+ const newVectors = [
133
+ {
134
+ id : "fail-with-test-error" ,
135
+ values : new Float32Array ( ) ,
136
+ } ,
137
+ ] ;
138
+
139
+ /** @type {Error | null } */
140
+ let error = null ;
141
+ try {
142
+ await IDX . insert ( newVectors ) ;
143
+ } catch ( e ) {
144
+ error = e ;
145
+ }
146
+
147
+ assert . equal (
148
+ error && error . message ,
149
+ "VECTOR_INSERT_ERROR (code = 9999): You asked me for this error"
150
+ ) ;
151
+ }
152
+ } ,
153
+ }
154
+
123
155
export const test_vector_search_vector_upsert = {
124
156
/**
125
157
* @param {unknown } ctr
Original file line number Diff line number Diff line change @@ -121,6 +121,15 @@ export default {
121
121
} else if ( request . method === "POST" && pathname . endsWith ( "/insert" ) ) {
122
122
/** @type {{vectors: Array<VectorizeVector>} } */
123
123
const data = await request . json ( ) ;
124
+ if ( data . vectors . find ( ( v ) => v . id == 'fail-with-test-error' ) ) {
125
+ return Response . json ( {
126
+ code : 9999 ,
127
+ error : 'You asked me for this error' ,
128
+ } , {
129
+ status : 400
130
+ } ) ;
131
+ } ;
132
+
124
133
return Response . json ( {
125
134
ids : [
126
135
...data . vectors . map ( ( { id } ) => id ) ,
Original file line number Diff line number Diff line change @@ -160,17 +160,22 @@ class VectorizeIndexImpl implements VectorizeIndex {
160
160
init
161
161
) ;
162
162
if ( res . status !== 200 ) {
163
+ let err : Error | null = null ;
164
+
163
165
try {
164
- const err = ( await res . json ( ) ) as VectorizeError ;
165
- throw new Error (
166
- `${ Operation [ operation ] } _ERROR ${
167
- typeof err . code === "number" ? ` (code = ${ err . code } )` : ""
168
- } : ${ err . error } `,
166
+ const errResponse = ( await res . json ( ) ) as VectorizeError ;
167
+ err = new Error (
168
+ `${ Operation [ operation ] } _ERROR ${ typeof errResponse . code === "number" ? `(code = ${ errResponse . code } )` : ""
169
+ } : ${ errResponse . error } `,
169
170
{
170
- cause : new Error ( err . error ) ,
171
+ cause : new Error ( errResponse . error ) ,
171
172
}
172
173
) ;
173
- } catch ( e ) {
174
+ } catch ( e ) { }
175
+
176
+ if ( err ) {
177
+ throw err ;
178
+ } else {
174
179
throw new Error (
175
180
`${ Operation [ operation ] } _ERROR: Status + ${ res . status } ` ,
176
181
{
You can’t perform that action at this time.
0 commit comments