From 799727f2066d69a13f90bd45db0e2c9dcc5daa9e Mon Sep 17 00:00:00 2001 From: Chris Price Date: Wed, 3 Jan 2024 14:10:28 -0800 Subject: [PATCH] chore: use options arg for handleError sig, for readability --- .../src/errors/cache-service-error-mapper.ts | 22 +- .../src/internal/cache-control-client.ts | 84 +-- .../src/internal/cache-data-client.ts | 555 +++++++++--------- .../src/internal/internal-auth-client.ts | 37 +- .../src/internal/leaderboard-data-client.ts | 85 +-- .../src/internal/pubsub-client.ts | 12 +- .../internal/vector-index-control-client.ts | 36 +- .../src/internal/vector-index-data-client.ts | 74 +-- .../src/internal/webhook-client.ts | 60 +- .../unit/cache-service-error-mapper.test.ts | 168 +++--- .../src/errors/cache-service-error-mapper.ts | 22 +- .../src/internal/auth-client.ts | 37 +- .../src/internal/cache-control-client.ts | 48 +- .../src/internal/cache-data-client.ts | 553 ++++++++--------- .../src/internal/leaderboard-data-client.ts | 85 +-- .../src/internal/pubsub-client.ts | 12 +- .../internal/vector-index-control-client.ts | 36 +- .../src/internal/vector-index-data-client.ts | 74 +-- .../src/internal/webhook-client.ts | 60 +- 19 files changed, 1050 insertions(+), 1010 deletions(-) diff --git a/packages/client-sdk-nodejs/src/errors/cache-service-error-mapper.ts b/packages/client-sdk-nodejs/src/errors/cache-service-error-mapper.ts index a0eeb5ad2..b6080d943 100644 --- a/packages/client-sdk-nodejs/src/errors/cache-service-error-mapper.ts +++ b/packages/client-sdk-nodejs/src/errors/cache-service-error-mapper.ts @@ -18,25 +18,27 @@ import { FailedPreconditionError, } from '../../src'; +export interface HandleCacheServiceErrorOptions { + err: ServiceError | null; + errorResponseFactoryFn: (err: SdkError) => unknown; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + resolveFn: (result: any) => void; + rejectFn: (err: SdkError) => void; +} + export class CacheServiceErrorMapper { private readonly throwOnError: boolean; constructor(throwOnError: boolean) { this.throwOnError = throwOnError; } - handleError( - err: ServiceError | null, - errorResponseFactoryFn: (err: SdkError) => unknown, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - resolveFn: (result: any) => void, - rejectFn: (err: SdkError) => void - ): void { - const error = this.convertError(err); + handleError(opts: HandleCacheServiceErrorOptions): void { + const error = this.convertError(opts.err); if (this.throwOnError) { - rejectFn(error); + opts.rejectFn(error); } else { - resolveFn(errorResponseFactoryFn(error)); + opts.resolveFn(opts.errorResponseFactoryFn(error)); } } diff --git a/packages/client-sdk-nodejs/src/internal/cache-control-client.ts b/packages/client-sdk-nodejs/src/internal/cache-control-client.ts index 342ebff6c..128738a31 100644 --- a/packages/client-sdk-nodejs/src/internal/cache-control-client.ts +++ b/packages/client-sdk-nodejs/src/internal/cache-control-client.ts @@ -97,12 +97,12 @@ export class CacheControlClient { if (err.code === Status.ALREADY_EXISTS) { resolve(new CreateCache.AlreadyExists()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CreateCache.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CreateCache.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } else { resolve(new CreateCache.Success()); @@ -130,12 +130,12 @@ export class CacheControlClient { {interceptors: this.interceptors}, (err, _resp) => { if (err) { - this.cacheServiceErrorMapper.handleError( - err, - e => new DeleteCache.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new DeleteCache.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve(new DeleteCache.Success()); } @@ -170,12 +170,12 @@ export class CacheControlClient { if (resp) { resolve(new CacheFlush.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheFlush.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheFlush.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -191,12 +191,12 @@ export class CacheControlClient { .getClient() .ListCaches(request, {interceptors: this.interceptors}, (err, resp) => { if (err || !resp) { - this.cacheServiceErrorMapper.handleError( - err, - e => new ListCaches.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new ListCaches.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { const caches = resp.cache.map(cache => { const cacheName = cache.cache_name; @@ -241,12 +241,12 @@ export class CacheControlClient { {interceptors: this.interceptors}, (err, resp) => { if (err) { - this.cacheServiceErrorMapper.handleError( - err, - e => new CreateSigningKey.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CreateSigningKey.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { const signingKey = new _SigningKey(resp?.key, resp?.expires_at); resolve(new CreateSigningKey.Success(endpoint, signingKey)); @@ -267,12 +267,12 @@ export class CacheControlClient { .getClient() .RevokeSigningKey(request, {interceptors: this.interceptors}, err => { if (err) { - this.cacheServiceErrorMapper.handleError( - err, - e => new RevokeSigningKey.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new RevokeSigningKey.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve(new RevokeSigningKey.Success()); } @@ -294,12 +294,12 @@ export class CacheControlClient { {interceptors: this.interceptors}, (err, resp) => { if (err || !resp) { - this.cacheServiceErrorMapper.handleError( - err, - e => new ListSigningKeys.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new ListSigningKeys.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { const signingKeys = resp.signing_key.map( sk => new _SigningKey(sk.key_id, sk.expires_at) diff --git a/packages/client-sdk-nodejs/src/internal/cache-data-client.ts b/packages/client-sdk-nodejs/src/internal/cache-data-client.ts index c5225f3b9..2bcc98f8f 100644 --- a/packages/client-sdk-nodejs/src/internal/cache-data-client.ts +++ b/packages/client-sdk-nodejs/src/internal/cache-data-client.ts @@ -338,12 +338,12 @@ export class CacheDataClient implements IDataClient { if (resp) { resolve(new CacheSet.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSet.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheSet.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -384,12 +384,12 @@ export class CacheDataClient implements IDataClient { } else if (resp?.found) { resolve(new CacheSetFetch.Hit(resp.found.elements)); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSetFetch.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheSetFetch.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -440,12 +440,12 @@ export class CacheDataClient implements IDataClient { }, err => { if (err) { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSetAddElements.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheSetAddElements.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve(new CacheSetAddElements.Success()); } @@ -497,12 +497,12 @@ export class CacheDataClient implements IDataClient { }, err => { if (err) { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSetRemoveElements.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheSetRemoveElements.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve(new CacheSetRemoveElements.Success()); } @@ -583,12 +583,12 @@ export class CacheDataClient implements IDataClient { break; } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSetIfNotExists.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheSetIfNotExists.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -627,12 +627,12 @@ export class CacheDataClient implements IDataClient { if (resp) { resolve(new CacheDelete.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheDelete.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheDelete.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -694,12 +694,12 @@ export class CacheDataClient implements IDataClient { break; } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheGet.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheGet.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -771,12 +771,13 @@ export class CacheDataClient implements IDataClient { if (resp) { resolve(new CacheListConcatenateBack.Success(resp.list_length)); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheListConcatenateBack.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheListConcatenateBack.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -848,12 +849,13 @@ export class CacheDataClient implements IDataClient { if (resp) { resolve(new CacheListConcatenateFront.Success(resp.list_length)); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheListConcatenateFront.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheListConcatenateFront.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -923,12 +925,12 @@ export class CacheDataClient implements IDataClient { } else if (resp?.found) { resolve(new CacheListFetch.Hit(resp.found.values)); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheListFetch.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheListFetch.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1004,12 +1006,12 @@ export class CacheDataClient implements IDataClient { if (resp) { resolve(new CacheListRetain.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheListRetain.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheListRetain.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1054,12 +1056,12 @@ export class CacheDataClient implements IDataClient { } else if (resp?.found) { resolve(new CacheListLength.Hit(resp.found.length)); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheListLength.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheListLength.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1108,12 +1110,12 @@ export class CacheDataClient implements IDataClient { } else if (resp?.found) { resolve(new CacheListPopBack.Hit(resp.found.back)); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheListPopBack.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheListPopBack.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1162,12 +1164,12 @@ export class CacheDataClient implements IDataClient { } else if (resp?.found) { resolve(new CacheListPopFront.Hit(resp.found.front)); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheListPopFront.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheListPopFront.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1235,12 +1237,12 @@ export class CacheDataClient implements IDataClient { if (resp) { resolve(new CacheListPushBack.Success(resp.list_length)); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheListPushBack.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheListPushBack.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1308,12 +1310,12 @@ export class CacheDataClient implements IDataClient { if (resp) { resolve(new CacheListPushFront.Success(resp.list_length)); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheListPushFront.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheListPushFront.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1366,12 +1368,12 @@ export class CacheDataClient implements IDataClient { if (resp) { resolve(new CacheListRemoveValue.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheListRemoveValue.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheListRemoveValue.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1420,12 +1422,12 @@ export class CacheDataClient implements IDataClient { } else if (resp?.missing) { resolve(new CacheDictionaryFetch.Miss()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheDictionaryFetch.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheDictionaryFetch.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1491,12 +1493,12 @@ export class CacheDataClient implements IDataClient { if (resp) { resolve(new CacheDictionarySetField.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheDictionarySetField.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheDictionarySetField.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1565,12 +1567,13 @@ export class CacheDataClient implements IDataClient { if (resp) { resolve(new CacheDictionarySetFields.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheDictionarySetFields.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheDictionarySetFields.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1649,12 +1652,13 @@ export class CacheDataClient implements IDataClient { ); } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheDictionaryGetField.Error(e, field), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheDictionaryGetField.Error(e, field), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1716,12 +1720,13 @@ export class CacheDataClient implements IDataClient { } else if (resp?.dictionary === 'missing') { resolve(new CacheDictionaryGetFields.Miss()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheDictionaryGetFields.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheDictionaryGetFields.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1778,12 +1783,13 @@ export class CacheDataClient implements IDataClient { if (resp) { resolve(new CacheDictionaryRemoveField.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheDictionaryRemoveField.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheDictionaryRemoveField.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1840,12 +1846,13 @@ export class CacheDataClient implements IDataClient { if (resp) { resolve(new CacheDictionaryRemoveFields.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheDictionaryRemoveFields.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheDictionaryRemoveFields.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1897,12 +1904,12 @@ export class CacheDataClient implements IDataClient { } else if (resp?.found) { resolve(new CacheDictionaryLength.Hit(resp.found.length)); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheDictionaryLength.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheDictionaryLength.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1964,12 +1971,12 @@ export class CacheDataClient implements IDataClient { resolve(new CacheIncrement.Success(0)); } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheIncrement.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheIncrement.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -2042,12 +2049,13 @@ export class CacheDataClient implements IDataClient { resolve(new CacheDictionaryIncrement.Success(0)); } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheDictionaryIncrement.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheDictionaryIncrement.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -2117,12 +2125,13 @@ export class CacheDataClient implements IDataClient { if (resp) { resolve(new CacheSortedSetPutElement.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSortedSetPutElement.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheSortedSetPutElement.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -2193,12 +2202,13 @@ export class CacheDataClient implements IDataClient { if (resp) { resolve(new CacheSortedSetPutElements.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSortedSetPutElements.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheSortedSetPutElements.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -2308,12 +2318,12 @@ export class CacheDataClient implements IDataClient { ); } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSortedSetFetch.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheSortedSetFetch.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -2452,12 +2462,12 @@ export class CacheDataClient implements IDataClient { ); } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSortedSetFetch.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheSortedSetFetch.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -2524,12 +2534,12 @@ export class CacheDataClient implements IDataClient { resolve(new CacheSortedSetGetRank.Hit(resp.element_rank.rank)); } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSortedSetGetRank.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheSortedSetGetRank.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -2618,12 +2628,13 @@ export class CacheDataClient implements IDataClient { }); resolve(new CacheSortedSetGetScores.Hit(elements, values)); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSortedSetGetScores.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheSortedSetGetScores.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -2698,12 +2709,13 @@ export class CacheDataClient implements IDataClient { resolve(new CacheSortedSetIncrementScore.Success(0)); } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSortedSetIncrementScore.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheSortedSetIncrementScore.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -2759,12 +2771,13 @@ export class CacheDataClient implements IDataClient { }, err => { if (err) { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSortedSetRemoveElement.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheSortedSetRemoveElement.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve(new CacheSortedSetRemoveElement.Success()); } @@ -2822,12 +2835,13 @@ export class CacheDataClient implements IDataClient { }, err => { if (err) { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSortedSetRemoveElements.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheSortedSetRemoveElements.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve(new CacheSortedSetRemoveElements.Success()); } @@ -2887,12 +2901,12 @@ export class CacheDataClient implements IDataClient { resolve(new CacheSortedSetLength.Hit(resp.found.length)); } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSortedSetLength.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheSortedSetLength.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -2973,12 +2987,13 @@ export class CacheDataClient implements IDataClient { resolve(new CacheSortedSetLengthByScore.Hit(resp.found.length)); } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSortedSetLengthByScore.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheSortedSetLengthByScore.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -3108,12 +3123,12 @@ export class CacheDataClient implements IDataClient { ) ); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheItemGetType.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheItemGetType.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -3152,12 +3167,12 @@ export class CacheDataClient implements IDataClient { } else if (resp?.found) { resolve(new CacheItemGetTtl.Hit(resp.found.remaining_ttl_millis)); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheItemGetTtl.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheItemGetTtl.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -3204,12 +3219,12 @@ export class CacheDataClient implements IDataClient { if (resp) { resolve(new CacheKeyExists.Success(resp.exists)); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheKeyExists.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheKeyExists.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -3269,12 +3284,12 @@ export class CacheDataClient implements IDataClient { } else if (resp?.set) { resolve(new CacheUpdateTtl.Set()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheUpdateTtl.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheUpdateTtl.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -3321,12 +3336,12 @@ export class CacheDataClient implements IDataClient { if (resp) { resolve(new CacheKeysExist.Success(resp.exists)); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheKeysExist.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheKeysExist.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -3386,12 +3401,12 @@ export class CacheDataClient implements IDataClient { } else if (resp?.set) { resolve(new CacheIncreaseTtl.Set()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheIncreaseTtl.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheIncreaseTtl.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -3451,12 +3466,12 @@ export class CacheDataClient implements IDataClient { } else if (resp?.set) { resolve(new CacheDecreaseTtl.Set()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheDecreaseTtl.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheDecreaseTtl.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); diff --git a/packages/client-sdk-nodejs/src/internal/internal-auth-client.ts b/packages/client-sdk-nodejs/src/internal/internal-auth-client.ts index e18dab066..0f2ce6fb6 100644 --- a/packages/client-sdk-nodejs/src/internal/internal-auth-client.ts +++ b/packages/client-sdk-nodejs/src/internal/internal-auth-client.ts @@ -124,12 +124,12 @@ export class InternalAuthClient implements IAuthClient { {interceptors: this.interceptors}, (err, resp) => { if (err || !resp) { - this.cacheServiceErrorMapper.handleError( - err, - e => new GenerateApiKey.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new GenerateApiKey.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve( new GenerateApiKey.Success( @@ -169,12 +169,12 @@ export class InternalAuthClient implements IAuthClient { {interceptors: this.interceptors}, (err, resp) => { if (err || !resp) { - this.cacheServiceErrorMapper.handleError( - err, - e => new RefreshApiKey.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new RefreshApiKey.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve( new RefreshApiKey.Success( @@ -245,12 +245,13 @@ export class InternalAuthClient implements IAuthClient { {interceptors: this.interceptors}, (err, resp) => { if (err || !resp) { - this.cacheServiceErrorMapper.handleError( - err, - e => new GenerateDisposableToken.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new GenerateDisposableToken.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve( new GenerateDisposableToken.Success( diff --git a/packages/client-sdk-nodejs/src/internal/leaderboard-data-client.ts b/packages/client-sdk-nodejs/src/internal/leaderboard-data-client.ts index 4404b776e..215542a63 100644 --- a/packages/client-sdk-nodejs/src/internal/leaderboard-data-client.ts +++ b/packages/client-sdk-nodejs/src/internal/leaderboard-data-client.ts @@ -194,12 +194,12 @@ export class LeaderboardDataClient implements ILeaderboardDataClient { if (resp) { resolve(new LeaderboardUpsert.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new LeaderboardUpsert.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new LeaderboardUpsert.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -291,12 +291,12 @@ export class LeaderboardDataClient implements ILeaderboardDataClient { .elements; resolve(new LeaderboardFetch.Success(foundElements)); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new LeaderboardFetch.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new LeaderboardFetch.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -365,12 +365,12 @@ export class LeaderboardDataClient implements ILeaderboardDataClient { .elements; resolve(new LeaderboardFetch.Success(foundElements)); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new LeaderboardFetch.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new LeaderboardFetch.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -423,12 +423,12 @@ export class LeaderboardDataClient implements ILeaderboardDataClient { .elements; resolve(new LeaderboardFetch.Success(foundElements)); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new LeaderboardFetch.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new LeaderboardFetch.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -467,12 +467,12 @@ export class LeaderboardDataClient implements ILeaderboardDataClient { .count; resolve(new LeaderboardLength.Success(length)); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new LeaderboardLength.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new LeaderboardLength.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -519,12 +519,13 @@ export class LeaderboardDataClient implements ILeaderboardDataClient { if (resp) { resolve(new LeaderboardRemoveElements.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new LeaderboardRemoveElements.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new LeaderboardRemoveElements.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -561,12 +562,12 @@ export class LeaderboardDataClient implements ILeaderboardDataClient { if (resp) { resolve(new LeaderboardDelete.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new LeaderboardDelete.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new LeaderboardDelete.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); diff --git a/packages/client-sdk-nodejs/src/internal/pubsub-client.ts b/packages/client-sdk-nodejs/src/internal/pubsub-client.ts index d16fe1064..7b129c2ae 100644 --- a/packages/client-sdk-nodejs/src/internal/pubsub-client.ts +++ b/packages/client-sdk-nodejs/src/internal/pubsub-client.ts @@ -119,12 +119,12 @@ export class PubsubClient extends AbstractPubsubClient { if (resp) { resolve(new TopicPublish.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new TopicPublish.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new TopicPublish.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); diff --git a/packages/client-sdk-nodejs/src/internal/vector-index-control-client.ts b/packages/client-sdk-nodejs/src/internal/vector-index-control-client.ts index aac9c4346..85f2141eb 100644 --- a/packages/client-sdk-nodejs/src/internal/vector-index-control-client.ts +++ b/packages/client-sdk-nodejs/src/internal/vector-index-control-client.ts @@ -130,12 +130,12 @@ export class VectorIndexControlClient implements IVectorIndexControlClient { if (err.code === Status.ALREADY_EXISTS) { resolve(new CreateVectorIndex.AlreadyExists()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CreateVectorIndex.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CreateVectorIndex.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } else { resolve(new CreateVectorIndex.Success()); @@ -158,12 +158,12 @@ export class VectorIndexControlClient implements IVectorIndexControlClient { if (err || !resp) { // TODO: `Argument of type 'unknown' is not assignable to parameter of type 'Error'.` // I don't see how this is different from the other methods here. So, yeah, what? - this.cacheServiceErrorMapper.handleError( - err, - e => new ListVectorIndexes.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new ListVectorIndexes.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { const indexes = resp.indexes.map(index => { let similarityMetric: VectorSimilarityMetric = @@ -219,12 +219,12 @@ export class VectorIndexControlClient implements IVectorIndexControlClient { // eslint-disable-next-line @typescript-eslint/no-unused-vars (err, resp) => { if (err) { - this.cacheServiceErrorMapper.handleError( - err, - e => new DeleteVectorIndex.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new DeleteVectorIndex.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve(new DeleteVectorIndex.Success()); } diff --git a/packages/client-sdk-nodejs/src/internal/vector-index-data-client.ts b/packages/client-sdk-nodejs/src/internal/vector-index-data-client.ts index 7aa05c863..c471bca1f 100644 --- a/packages/client-sdk-nodejs/src/internal/vector-index-data-client.ts +++ b/packages/client-sdk-nodejs/src/internal/vector-index-data-client.ts @@ -180,12 +180,12 @@ export class VectorIndexDataClient implements IVectorIndexDataClient { if (resp) { resolve(new VectorUpsertItemBatch.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new VectorUpsertItemBatch.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new VectorUpsertItemBatch.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -220,12 +220,12 @@ export class VectorIndexDataClient implements IVectorIndexDataClient { if (resp) { resolve(new VectorDeleteItemBatch.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new VectorDeleteItemBatch.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new VectorDeleteItemBatch.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -345,12 +345,12 @@ export class VectorIndexDataClient implements IVectorIndexDataClient { ) ); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new VectorSearch.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new VectorSearch.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -419,12 +419,13 @@ export class VectorIndexDataClient implements IVectorIndexDataClient { ) ); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new VectorSearchAndFetchVectors.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new VectorSearchAndFetchVectors.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -498,12 +499,12 @@ export class VectorIndexDataClient implements IVectorIndexDataClient { ) ); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new VectorGetItemBatch.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new VectorGetItemBatch.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -576,12 +577,13 @@ export class VectorIndexDataClient implements IVectorIndexDataClient { ) ); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new VectorGetItemMetadataBatch.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new VectorGetItemMetadataBatch.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); diff --git a/packages/client-sdk-nodejs/src/internal/webhook-client.ts b/packages/client-sdk-nodejs/src/internal/webhook-client.ts index df8e96770..160952611 100644 --- a/packages/client-sdk-nodejs/src/internal/webhook-client.ts +++ b/packages/client-sdk-nodejs/src/internal/webhook-client.ts @@ -77,12 +77,12 @@ export class WebhookClient implements IWebhookClient { {interceptors: this.unaryInterceptors}, (err, _resp) => { if (err) { - this.cacheServiceErrorMapper.handleError( - err, - e => new DeleteWebhook.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new DeleteWebhook.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve(new DeleteWebhook.Success()); } @@ -106,12 +106,12 @@ export class WebhookClient implements IWebhookClient { {interceptors: this.unaryInterceptors}, (err, resp) => { if (err || !resp) { - this.cacheServiceErrorMapper.handleError( - err, - e => new ListWebhooks.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new ListWebhooks.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { const webhooks = resp.webhook.map(wh => { const webhook: Webhook = { @@ -162,12 +162,12 @@ export class WebhookClient implements IWebhookClient { {interceptors: this.unaryInterceptors}, (err, resp) => { if (err || !resp) { - this.cacheServiceErrorMapper.handleError( - err, - e => new PutWebhook.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new PutWebhook.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve(new PutWebhook.Success(resp.secret_string)); } @@ -196,12 +196,12 @@ export class WebhookClient implements IWebhookClient { {interceptors: this.unaryInterceptors}, (err, resp) => { if (err || !resp) { - this.cacheServiceErrorMapper.handleError( - err, - e => new GetWebhookSecret.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new GetWebhookSecret.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve( new GetWebhookSecret.Success({ @@ -242,12 +242,12 @@ export class WebhookClient implements IWebhookClient { {interceptors: this.unaryInterceptors}, (err, resp) => { if (err || !resp) { - this.cacheServiceErrorMapper.handleError( - err, - e => new RotateWebhookSecret.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new RotateWebhookSecret.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve( new RotateWebhookSecret.Success({ diff --git a/packages/client-sdk-nodejs/test/unit/cache-service-error-mapper.test.ts b/packages/client-sdk-nodejs/test/unit/cache-service-error-mapper.test.ts index 60aa89ca5..371118d9f 100644 --- a/packages/client-sdk-nodejs/test/unit/cache-service-error-mapper.test.ts +++ b/packages/client-sdk-nodejs/test/unit/cache-service-error-mapper.test.ts @@ -49,32 +49,32 @@ describe('CacheServiceErrorMapper', () => { it('should return permission denied error when Status.PERMISSION_DENIED', () => { const serviceError = generateServiceError(Status.PERMISSION_DENIED); - cacheServiceErrorMapper.handleError( - serviceError, - errorResponseFactoryFn, - resolveFn, - rejectFn - ); + cacheServiceErrorMapper.handleError({ + err: serviceError, + errorResponseFactoryFn: errorResponseFactoryFn, + resolveFn: resolveFn, + rejectFn: rejectFn, + }); expect(resolved).toBeInstanceOf(PermissionError); }); it('should return invalid argument error when grpc status is INVALID_ARGUMENT', () => { const serviceError = generateServiceError(Status.INVALID_ARGUMENT); - cacheServiceErrorMapper.handleError( - serviceError, - errorResponseFactoryFn, - resolveFn, - rejectFn - ); + cacheServiceErrorMapper.handleError({ + err: serviceError, + errorResponseFactoryFn: errorResponseFactoryFn, + resolveFn: resolveFn, + rejectFn: rejectFn, + }); expect(resolved).toBeInstanceOf(InvalidArgumentError); }); it('should return failed precondition error when grpc status is FAILED_PRECONDITION', () => { const serviceError = generateServiceError(Status.FAILED_PRECONDITION); - cacheServiceErrorMapper.handleError( - serviceError, - errorResponseFactoryFn, - resolveFn, - rejectFn - ); + cacheServiceErrorMapper.handleError({ + err: serviceError, + errorResponseFactoryFn: errorResponseFactoryFn, + resolveFn: resolveFn, + rejectFn: rejectFn, + }); expect(resolved).toBeInstanceOf(FailedPreconditionError); }); it('should return bad request error when grpc status is OUT_OF_RANGE or UNIMPLEMENTED', () => { @@ -83,43 +83,43 @@ describe('CacheServiceErrorMapper', () => { generateServiceError(Status.UNIMPLEMENTED), ]; serviceErrors.forEach(e => { - cacheServiceErrorMapper.handleError( - e, - errorResponseFactoryFn, - resolveFn, - rejectFn - ); + cacheServiceErrorMapper.handleError({ + err: e, + errorResponseFactoryFn: errorResponseFactoryFn, + resolveFn: resolveFn, + rejectFn: rejectFn, + }); expect(resolved).toBeInstanceOf(BadRequestError); }); }); it('should return cache not found error when grpc status is NOT_FOUND', () => { const serviceError = generateServiceError(Status.NOT_FOUND); - cacheServiceErrorMapper.handleError( - serviceError, - errorResponseFactoryFn, - resolveFn, - rejectFn - ); + cacheServiceErrorMapper.handleError({ + err: serviceError, + errorResponseFactoryFn: errorResponseFactoryFn, + resolveFn: resolveFn, + rejectFn: rejectFn, + }); expect(resolved).toBeInstanceOf(NotFoundError); }); it('should return unavailable error when grpc status is UNAVAILABLE', () => { const serviceError = generateServiceError(Status.UNAVAILABLE); - cacheServiceErrorMapper.handleError( - serviceError, - errorResponseFactoryFn, - resolveFn, - rejectFn - ); + cacheServiceErrorMapper.handleError({ + err: serviceError, + errorResponseFactoryFn: errorResponseFactoryFn, + resolveFn: resolveFn, + rejectFn: rejectFn, + }); expect(resolved).toBeInstanceOf(ServerUnavailableError); }); it('should return unknown service error when grpc status is UNKNOWN', () => { const serviceError = generateServiceError(Status.UNKNOWN); - cacheServiceErrorMapper.handleError( - serviceError, - errorResponseFactoryFn, - resolveFn, - rejectFn - ); + cacheServiceErrorMapper.handleError({ + err: serviceError, + errorResponseFactoryFn: errorResponseFactoryFn, + resolveFn: resolveFn, + rejectFn: rejectFn, + }); expect(resolved).toBeInstanceOf(UnknownServiceError); }); it('should return internal server error when grpc status is DATA_LOSS, INTERNAL, ABORTED', () => { @@ -129,63 +129,63 @@ describe('CacheServiceErrorMapper', () => { generateServiceError(Status.ABORTED), ]; serviceErrors.forEach(e => { - cacheServiceErrorMapper.handleError( - e, - errorResponseFactoryFn, - resolveFn, - rejectFn - ); + cacheServiceErrorMapper.handleError({ + err: e, + errorResponseFactoryFn: errorResponseFactoryFn, + resolveFn: resolveFn, + rejectFn: rejectFn, + }); expect(resolved).toBeInstanceOf(InternalServerError); }); }); it('should return cancelled error when grpc status is CANCELLED', () => { const serviceError = generateServiceError(Status.CANCELLED); - cacheServiceErrorMapper.handleError( - serviceError, - errorResponseFactoryFn, - resolveFn, - rejectFn - ); + cacheServiceErrorMapper.handleError({ + err: serviceError, + errorResponseFactoryFn: errorResponseFactoryFn, + resolveFn: resolveFn, + rejectFn: rejectFn, + }); expect(resolved).toBeInstanceOf(CancelledError); }); it('should return timeout error when grpc status is DEADLINE_EXCEEDED', () => { const serviceError = generateServiceError(Status.DEADLINE_EXCEEDED); - cacheServiceErrorMapper.handleError( - serviceError, - errorResponseFactoryFn, - resolveFn, - rejectFn - ); + cacheServiceErrorMapper.handleError({ + err: serviceError, + errorResponseFactoryFn: errorResponseFactoryFn, + resolveFn: resolveFn, + rejectFn: rejectFn, + }); expect(resolved).toBeInstanceOf(TimeoutError); }); it('should return authentication error when grpc status is UNAUTHENTICATED', () => { const serviceError = generateServiceError(Status.UNAUTHENTICATED); - cacheServiceErrorMapper.handleError( - serviceError, - errorResponseFactoryFn, - resolveFn, - rejectFn - ); + cacheServiceErrorMapper.handleError({ + err: serviceError, + errorResponseFactoryFn: errorResponseFactoryFn, + resolveFn: resolveFn, + rejectFn: rejectFn, + }); expect(resolved).toBeInstanceOf(AuthenticationError); }); it('should return limit exceeded error when grpc status is RESOURCE_EXHAUSTED', () => { const serviceError = generateServiceError(Status.RESOURCE_EXHAUSTED); - cacheServiceErrorMapper.handleError( - serviceError, - errorResponseFactoryFn, - resolveFn, - rejectFn - ); + cacheServiceErrorMapper.handleError({ + err: serviceError, + errorResponseFactoryFn: errorResponseFactoryFn, + resolveFn: resolveFn, + rejectFn: rejectFn, + }); expect(resolved).toBeInstanceOf(LimitExceededError); }); it('should return already exists error when grpc status is ALREADY_EXISTS', () => { const serviceError = generateServiceError(Status.ALREADY_EXISTS); - cacheServiceErrorMapper.handleError( - serviceError, - errorResponseFactoryFn, - resolveFn, - rejectFn - ); + cacheServiceErrorMapper.handleError({ + err: serviceError, + errorResponseFactoryFn: errorResponseFactoryFn, + resolveFn: resolveFn, + rejectFn: rejectFn, + }); expect(resolved).toBeInstanceOf(AlreadyExistsError); }); @@ -194,12 +194,12 @@ describe('CacheServiceErrorMapper', () => { it('should reject with LimitExceeded when grpc status is RESOURCE_EXHAUSTED', () => { const serviceError = generateServiceError(Status.RESOURCE_EXHAUSTED); - mapperWithThrowOnErrors.handleError( - serviceError, - errorResponseFactoryFn, - resolveFn, - rejectFn - ); + mapperWithThrowOnErrors.handleError({ + err: serviceError, + errorResponseFactoryFn: errorResponseFactoryFn, + resolveFn: resolveFn, + rejectFn: rejectFn, + }); expect(rejected).toBeInstanceOf(LimitExceededError); }); }); diff --git a/packages/client-sdk-web/src/errors/cache-service-error-mapper.ts b/packages/client-sdk-web/src/errors/cache-service-error-mapper.ts index 252d226b0..18d3395c4 100644 --- a/packages/client-sdk-web/src/errors/cache-service-error-mapper.ts +++ b/packages/client-sdk-web/src/errors/cache-service-error-mapper.ts @@ -17,6 +17,14 @@ import { } from '../../src'; import {RpcError, StatusCode} from 'grpc-web'; +export interface HandleCacheServiceErrorOptions { + err: RpcError | null; + errorResponseFactoryFn: (err: SdkError) => unknown; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + resolveFn: (result: any) => void; + rejectFn: (err: SdkError) => void; +} + export class CacheServiceErrorMapper { private readonly throwOnErrors: boolean; @@ -24,18 +32,12 @@ export class CacheServiceErrorMapper { this.throwOnErrors = throwOnErrors; } - handleError( - err: RpcError | null, - errorResponseFactoryFn: (err: SdkError) => unknown, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - resolveFn: (result: any) => void, - rejectFn: (err: SdkError) => void - ): void { - const error = this.convertError(err); + handleError(opts: HandleCacheServiceErrorOptions): void { + const error = this.convertError(opts.err); if (this.throwOnErrors) { - rejectFn(error); + opts.rejectFn(error); } else { - resolveFn(errorResponseFactoryFn(error)); + opts.resolveFn(opts.errorResponseFactoryFn(error)); } } diff --git a/packages/client-sdk-web/src/internal/auth-client.ts b/packages/client-sdk-web/src/internal/auth-client.ts index 87d81edbe..05641079f 100644 --- a/packages/client-sdk-web/src/internal/auth-client.ts +++ b/packages/client-sdk-web/src/internal/auth-client.ts @@ -139,12 +139,12 @@ export class InternalWebGrpcAuthClient< this.clientMetadataProvider.createClientMetadata(), (err, resp) => { if (err || !resp) { - this.cacheServiceErrorMapper.handleError( - err, - e => new GenerateApiKey.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new GenerateApiKey.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve( new GenerateApiKey.Success( @@ -183,12 +183,12 @@ export class InternalWebGrpcAuthClient< this.clientMetadataProvider.createClientMetadata(), (err, resp) => { if (err || !resp) { - this.cacheServiceErrorMapper.handleError( - err, - e => new RefreshApiKey.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new RefreshApiKey.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve( new RefreshApiKey.Success( @@ -259,12 +259,13 @@ export class InternalWebGrpcAuthClient< this.clientMetadataProvider.createClientMetadata(), (err, resp) => { if (err || !resp) { - this.cacheServiceErrorMapper.handleError( - err, - e => new GenerateDisposableToken.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new GenerateDisposableToken.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve( new GenerateDisposableToken.Success( diff --git a/packages/client-sdk-web/src/internal/cache-control-client.ts b/packages/client-sdk-web/src/internal/cache-control-client.ts index f55f71a7b..2fe0f817f 100644 --- a/packages/client-sdk-web/src/internal/cache-control-client.ts +++ b/packages/client-sdk-web/src/internal/cache-control-client.ts @@ -87,12 +87,12 @@ export class CacheControlClient< if (err.code === StatusCode.ALREADY_EXISTS) { resolve(new CreateCache.AlreadyExists()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CreateCache.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CreateCache.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } else { resolve(new CreateCache.Success()); @@ -117,12 +117,12 @@ export class CacheControlClient< this.clientMetadataProvider.createClientMetadata(), (err, _resp) => { if (err) { - this.cacheServiceErrorMapper.handleError( - err, - e => new DeleteCache.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new DeleteCache.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve(new DeleteCache.Success()); } @@ -154,12 +154,12 @@ export class CacheControlClient< if (resp) { resolve(new CacheFlush.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheFlush.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheFlush.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -176,12 +176,12 @@ export class CacheControlClient< this.clientMetadataProvider.createClientMetadata(), (err, resp) => { if (err) { - this.cacheServiceErrorMapper.handleError( - err, - e => new ListCaches.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new ListCaches.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { const caches = resp.getCacheList().map(cache => { const cacheName = cache.getCacheName(); diff --git a/packages/client-sdk-web/src/internal/cache-data-client.ts b/packages/client-sdk-web/src/internal/cache-data-client.ts index b691db5ef..f0a3e1a7c 100644 --- a/packages/client-sdk-web/src/internal/cache-data-client.ts +++ b/packages/client-sdk-web/src/internal/cache-data-client.ts @@ -249,12 +249,12 @@ export class CacheDataClient< break; } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheGet.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheGet.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -314,12 +314,12 @@ export class CacheDataClient< if (resp) { resolve(new CacheSet.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSet.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheSet.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -396,12 +396,12 @@ export class CacheDataClient< break; } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSetIfNotExists.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheSetIfNotExists.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -439,12 +439,12 @@ export class CacheDataClient< if (resp) { resolve(new CacheDelete.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheDelete.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheDelete.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -504,12 +504,12 @@ export class CacheDataClient< resolve(new CacheIncrement.Success(0)); } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheIncrement.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheIncrement.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -551,12 +551,12 @@ export class CacheDataClient< } else if (resp?.getMissing()) { resolve(new CacheSetFetch.Miss()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSetFetch.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheSetFetch.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -606,12 +606,12 @@ export class CacheDataClient< }, err => { if (err) { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSetAddElements.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheSetAddElements.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve(new CacheSetAddElements.Success()); } @@ -660,12 +660,12 @@ export class CacheDataClient< }, err => { if (err) { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSetRemoveElements.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheSetRemoveElements.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve(new CacheSetRemoveElements.Success()); } @@ -738,12 +738,13 @@ export class CacheDataClient< if (resp) { resolve(new CacheListConcatenateBack.Success(resp.getListLength())); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheListConcatenateBack.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheListConcatenateBack.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -816,12 +817,13 @@ export class CacheDataClient< new CacheListConcatenateFront.Success(resp.getListLength()) ); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheListConcatenateFront.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheListConcatenateFront.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -897,12 +899,12 @@ export class CacheDataClient< resolve(new CacheListFetch.Miss()); } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheListFetch.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheListFetch.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -978,12 +980,12 @@ export class CacheDataClient< if (resp) { resolve(new CacheListRetain.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheListRetain.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheListRetain.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1036,12 +1038,12 @@ export class CacheDataClient< resolve(new CacheListLength.Hit(len)); } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheListLength.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheListLength.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1093,12 +1095,12 @@ export class CacheDataClient< resolve(new CacheListPopBack.Hit(this.convertToUint8Array(val))); } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheListPopBack.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheListPopBack.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1150,12 +1152,12 @@ export class CacheDataClient< resolve(new CacheListPopFront.Hit(this.convertToUint8Array(val))); } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheListPopFront.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheListPopFront.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1222,12 +1224,12 @@ export class CacheDataClient< if (resp) { resolve(new CacheListPushBack.Success(resp.getListLength())); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheListPushBack.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheListPushBack.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1294,12 +1296,12 @@ export class CacheDataClient< if (resp) { resolve(new CacheListPushFront.Success(resp.getListLength())); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheListPushFront.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheListPushFront.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1351,12 +1353,12 @@ export class CacheDataClient< if (resp) { resolve(new CacheListRemoveValue.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheListRemoveValue.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheListRemoveValue.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1423,12 +1425,12 @@ export class CacheDataClient< if (resp) { resolve(new CacheDictionarySetField.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheDictionarySetField.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheDictionarySetField.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1496,12 +1498,13 @@ export class CacheDataClient< if (resp) { resolve(new CacheDictionarySetFields.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheDictionarySetFields.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheDictionarySetFields.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1586,16 +1589,16 @@ export class CacheDataClient< ); } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheDictionaryGetField.Error( e, this.convertToUint8Array(field) ), - resolve, - reject - ); + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1664,12 +1667,13 @@ export class CacheDataClient< } else if (resp?.getMissing()) { resolve(new CacheDictionaryGetFields.Miss()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheDictionaryGetFields.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheDictionaryGetFields.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1727,12 +1731,12 @@ export class CacheDataClient< } else if (resp?.getMissing()) { resolve(new CacheDictionaryFetch.Miss()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheDictionaryFetch.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheDictionaryFetch.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1804,12 +1808,13 @@ export class CacheDataClient< resolve(new CacheDictionaryIncrement.Success(0)); } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheDictionaryIncrement.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheDictionaryIncrement.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1863,12 +1868,13 @@ export class CacheDataClient< if (resp) { resolve(new CacheDictionaryRemoveField.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheDictionaryRemoveField.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheDictionaryRemoveField.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1922,12 +1928,13 @@ export class CacheDataClient< if (resp) { resolve(new CacheDictionaryRemoveFields.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheDictionaryRemoveFields.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheDictionaryRemoveFields.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -1982,12 +1989,12 @@ export class CacheDataClient< resolve(new CacheDictionaryLength.Hit(len)); } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheDictionaryLength.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheDictionaryLength.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -2091,12 +2098,12 @@ export class CacheDataClient< } else if (resp?.getMissing()) { resolve(new CacheSortedSetFetch.Miss()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSortedSetFetch.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheSortedSetFetch.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -2237,12 +2244,12 @@ export class CacheDataClient< ); } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSortedSetFetch.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheSortedSetFetch.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -2314,12 +2321,13 @@ export class CacheDataClient< if (resp) { resolve(new CacheSortedSetPutElement.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSortedSetPutElement.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheSortedSetPutElement.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -2389,12 +2397,13 @@ export class CacheDataClient< if (resp) { resolve(new CacheSortedSetPutElements.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSortedSetPutElements.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheSortedSetPutElements.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -2501,12 +2510,12 @@ export class CacheDataClient< ); } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSortedSetGetScores.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheSortedSetGetScores.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -2573,12 +2582,12 @@ export class CacheDataClient< resolve(new CacheSortedSetGetRank.Miss()); } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSortedSetGetRank.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheSortedSetGetRank.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -2654,12 +2663,13 @@ export class CacheDataClient< resolve(new CacheSortedSetIncrementScore.Success(0)); } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSortedSetIncrementScore.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheSortedSetIncrementScore.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -2711,12 +2721,13 @@ export class CacheDataClient< }, err => { if (err) { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSortedSetRemoveElement.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheSortedSetRemoveElement.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve(new CacheSortedSetRemoveElement.Success()); } @@ -2770,12 +2781,13 @@ export class CacheDataClient< }, err => { if (err) { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSortedSetRemoveElements.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheSortedSetRemoveElements.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve(new CacheSortedSetRemoveElements.Success()); } @@ -2834,12 +2846,12 @@ export class CacheDataClient< resolve(new CacheSortedSetLength.Hit(len)); } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSortedSetLength.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheSortedSetLength.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -2919,12 +2931,13 @@ export class CacheDataClient< resolve(new CacheSortedSetLengthByScore.Hit(len)); } } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheSortedSetLengthByScore.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new CacheSortedSetLengthByScore.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -2967,12 +2980,12 @@ export class CacheDataClient< } else if (resp?.getMissing()) { resolve(new CacheItemGetType.Miss()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheItemGetType.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheItemGetType.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -3012,12 +3025,12 @@ export class CacheDataClient< } else if (resp?.getMissing()) { resolve(new CacheItemGetTtl.Miss()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheItemGetTtl.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheItemGetTtl.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -3063,12 +3076,12 @@ export class CacheDataClient< if (resp) { resolve(new CacheKeyExists.Success(resp.getExistsList())); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheKeyExists.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheKeyExists.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -3117,12 +3130,12 @@ export class CacheDataClient< if (resp) { resolve(new CacheKeysExist.Success(resp.getExistsList())); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheKeysExist.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheKeysExist.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -3181,12 +3194,12 @@ export class CacheDataClient< } else if (resp?.getSet()) { resolve(new CacheUpdateTtl.Set()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheUpdateTtl.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheUpdateTtl.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -3245,12 +3258,12 @@ export class CacheDataClient< } else if (resp?.getSet()) { resolve(new CacheIncreaseTtl.Set()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheIncreaseTtl.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheIncreaseTtl.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -3309,12 +3322,12 @@ export class CacheDataClient< } else if (resp?.getSet()) { resolve(new CacheDecreaseTtl.Set()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CacheDecreaseTtl.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CacheDecreaseTtl.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); diff --git a/packages/client-sdk-web/src/internal/leaderboard-data-client.ts b/packages/client-sdk-web/src/internal/leaderboard-data-client.ts index e974a638e..a8d3e1414 100644 --- a/packages/client-sdk-web/src/internal/leaderboard-data-client.ts +++ b/packages/client-sdk-web/src/internal/leaderboard-data-client.ts @@ -151,12 +151,12 @@ export class LeaderboardDataClient< if (resp) { resolve(new LeaderboardUpsert.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new LeaderboardUpsert.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new LeaderboardUpsert.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -250,12 +250,12 @@ export class LeaderboardDataClient< ) ); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new LeaderboardFetch.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new LeaderboardFetch.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -325,12 +325,12 @@ export class LeaderboardDataClient< ) ); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new LeaderboardFetch.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new LeaderboardFetch.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -385,12 +385,12 @@ export class LeaderboardDataClient< ) ); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new LeaderboardFetch.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new LeaderboardFetch.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -427,12 +427,12 @@ export class LeaderboardDataClient< const length = resp.getCount(); resolve(new LeaderboardLength.Success(length)); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new LeaderboardLength.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new LeaderboardLength.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -478,12 +478,13 @@ export class LeaderboardDataClient< if (resp) { resolve(new LeaderboardRemoveElements.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new LeaderboardRemoveElements.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new LeaderboardRemoveElements.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -519,12 +520,12 @@ export class LeaderboardDataClient< if (resp) { resolve(new LeaderboardDelete.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new LeaderboardDelete.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new LeaderboardDelete.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); diff --git a/packages/client-sdk-web/src/internal/pubsub-client.ts b/packages/client-sdk-web/src/internal/pubsub-client.ts index 9e19dbfea..2ce72d3d6 100644 --- a/packages/client-sdk-web/src/internal/pubsub-client.ts +++ b/packages/client-sdk-web/src/internal/pubsub-client.ts @@ -103,12 +103,12 @@ export class PubsubClient< if (resp) { resolve(new TopicPublish.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new TopicPublish.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new TopicPublish.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); diff --git a/packages/client-sdk-web/src/internal/vector-index-control-client.ts b/packages/client-sdk-web/src/internal/vector-index-control-client.ts index 99de04771..bb09f33e4 100644 --- a/packages/client-sdk-web/src/internal/vector-index-control-client.ts +++ b/packages/client-sdk-web/src/internal/vector-index-control-client.ts @@ -129,12 +129,12 @@ export class VectorIndexControlClient< if (err.code === StatusCode.ALREADY_EXISTS) { resolve(new CreateVectorIndex.AlreadyExists()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new CreateVectorIndex.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new CreateVectorIndex.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } else { resolve(new CreateVectorIndex.Success()); @@ -153,12 +153,12 @@ export class VectorIndexControlClient< this.clientMetadataProvider.createClientMetadata(), (err, resp) => { if (err) { - this.cacheServiceErrorMapper.handleError( - err, - e => new ListVectorIndexes.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new ListVectorIndexes.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { const indexes: VectorIndexInfo[] = resp .getIndexesList() @@ -221,12 +221,12 @@ export class VectorIndexControlClient< this.clientMetadataProvider.createClientMetadata(), (err, _resp) => { if (err) { - this.cacheServiceErrorMapper.handleError( - err, - e => new DeleteVectorIndex.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new DeleteVectorIndex.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve(new DeleteVectorIndex.Success()); } diff --git a/packages/client-sdk-web/src/internal/vector-index-data-client.ts b/packages/client-sdk-web/src/internal/vector-index-data-client.ts index 3a47a84d8..249fbda3b 100644 --- a/packages/client-sdk-web/src/internal/vector-index-data-client.ts +++ b/packages/client-sdk-web/src/internal/vector-index-data-client.ts @@ -148,12 +148,12 @@ export class VectorIndexDataClient implements IVectorIndexDataClient { if (resp) { resolve(new VectorUpsertItemBatch.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new VectorUpsertItemBatch.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new VectorUpsertItemBatch.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -191,12 +191,12 @@ export class VectorIndexDataClient implements IVectorIndexDataClient { if (resp) { resolve(new VectorDeleteItemBatch.Success()); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new VectorDeleteItemBatch.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new VectorDeleteItemBatch.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -326,12 +326,12 @@ export class VectorIndexDataClient implements IVectorIndexDataClient { ) ); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new VectorSearch.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new VectorSearch.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -408,12 +408,13 @@ export class VectorIndexDataClient implements IVectorIndexDataClient { ) ); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new VectorSearchAndFetchVectors.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new VectorSearchAndFetchVectors.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -494,12 +495,12 @@ export class VectorIndexDataClient implements IVectorIndexDataClient { ) ); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new VectorGetItemBatch.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new VectorGetItemBatch.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); @@ -581,12 +582,13 @@ export class VectorIndexDataClient implements IVectorIndexDataClient { ) ); } else { - this.cacheServiceErrorMapper.handleError( - err, - e => new VectorGetItemMetadataBatch.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => + new VectorGetItemMetadataBatch.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } } ); diff --git a/packages/client-sdk-web/src/internal/webhook-client.ts b/packages/client-sdk-web/src/internal/webhook-client.ts index 4c91af503..4fd481e61 100644 --- a/packages/client-sdk-web/src/internal/webhook-client.ts +++ b/packages/client-sdk-web/src/internal/webhook-client.ts @@ -92,12 +92,12 @@ export class WebhookClient implements IWebhookClient { this.clientMetadataProvider.createClientMetadata(), (err, _resp) => { if (err) { - this.cacheServiceErrorMapper.handleError( - err, - e => new DeleteWebhook.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new DeleteWebhook.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve(new DeleteWebhook.Success()); } @@ -122,12 +122,12 @@ export class WebhookClient implements IWebhookClient { this.clientMetadataProvider.createClientMetadata(), (err, resp) => { if (err || !resp) { - this.cacheServiceErrorMapper.handleError( - err, - e => new ListWebhooks.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new ListWebhooks.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { const webhooks = resp.getWebhookList().map(wh => { const webhook: Webhook = { @@ -181,12 +181,12 @@ export class WebhookClient implements IWebhookClient { this.clientMetadataProvider.createClientMetadata(), (err, resp) => { if (err || !resp) { - this.cacheServiceErrorMapper.handleError( - err, - e => new PutWebhook.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new PutWebhook.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve(new PutWebhook.Success(resp.getSecretString())); } @@ -214,12 +214,12 @@ export class WebhookClient implements IWebhookClient { this.clientMetadataProvider.createClientMetadata(), (err, resp) => { if (err || !resp) { - this.cacheServiceErrorMapper.handleError( - err, - e => new GetWebhookSecret.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new GetWebhookSecret.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve( new GetWebhookSecret.Success({ @@ -258,12 +258,12 @@ export class WebhookClient implements IWebhookClient { this.clientMetadataProvider.createClientMetadata(), (err, resp) => { if (err || !resp) { - this.cacheServiceErrorMapper.handleError( - err, - e => new RotateWebhookSecret.Error(e), - resolve, - reject - ); + this.cacheServiceErrorMapper.handleError({ + err: err, + errorResponseFactoryFn: e => new RotateWebhookSecret.Error(e), + resolveFn: resolve, + rejectFn: reject, + }); } else { resolve( new RotateWebhookSecret.Success({