@@ -320,18 +320,19 @@ export function createSearchClient({
320
320
Math . min ( retryCount * 200 , 5000 ) ,
321
321
} : WaitForApiKeyOptions ,
322
322
requestOptions ?: RequestOptions
323
- ) : Promise < ApiError | GetApiKeyResponse > {
323
+ ) : Promise < GetApiKeyResponse | undefined > {
324
324
let retryCount = 0 ;
325
- const baseIteratorOptions : IterableOptions < ApiError | GetApiKeyResponse > =
326
- {
327
- aggregator : ( ) => ( retryCount += 1 ) ,
328
- error : {
329
- validate : ( ) => retryCount >= maxRetries ,
330
- message : ( ) =>
331
- `The maximum number of retries exceeded. (${ retryCount } /${ maxRetries } )` ,
332
- } ,
333
- timeout : ( ) => timeout ( retryCount ) ,
334
- } ;
325
+ const baseIteratorOptions : IterableOptions <
326
+ GetApiKeyResponse | undefined
327
+ > = {
328
+ aggregator : ( ) => ( retryCount += 1 ) ,
329
+ error : {
330
+ validate : ( ) => retryCount >= maxRetries ,
331
+ message : ( ) =>
332
+ `The maximum number of retries exceeded. (${ retryCount } /${ maxRetries } )` ,
333
+ } ,
334
+ timeout : ( ) => timeout ( retryCount ) ,
335
+ } ;
335
336
336
337
if ( operation === 'update' ) {
337
338
if ( ! apiKey ) {
@@ -366,9 +367,15 @@ export function createSearchClient({
366
367
return createIterablePromise ( {
367
368
...baseIteratorOptions ,
368
369
func : ( ) =>
369
- this . getApiKey ( { key } , requestOptions ) . catch ( ( error ) => error ) ,
370
- validate : ( error : ApiError ) =>
371
- operation === 'add' ? error . status !== 404 : error . status === 404 ,
370
+ this . getApiKey ( { key } , requestOptions ) . catch ( ( error : ApiError ) => {
371
+ if ( error . status === 404 ) {
372
+ return undefined ;
373
+ }
374
+
375
+ throw error ;
376
+ } ) ,
377
+ validate : ( response ) =>
378
+ operation === 'add' ? response !== undefined : response === undefined ,
372
379
} ) ;
373
380
} ,
374
381
0 commit comments