Skip to content

Commit

Permalink
chore: code cleanup, standardize logging (#1027)
Browse files Browse the repository at this point in the history
  • Loading branch information
bruuuuuuuce authored Nov 10, 2023
1 parent 3c05a03 commit 2604892
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 40 deletions.
56 changes: 29 additions & 27 deletions packages/client-sdk-nodejs/src/internal/cache-control-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,28 @@ export class CacheControlClient {
} catch (err) {
return new CreateCache.Error(normalizeSdkError(err as Error));
}
this.logger.info(`Creating cache: ${name}`);
this.logger.debug(`Creating cache: ${name}`);
const request = new grpcControl._CreateCacheRequest({
cache_name: name,
});
return await new Promise<CreateCache.Response>(resolve => {
this.clientWrapper.getClient().CreateCache(
request,
{interceptors: this.interceptors},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
(err, resp) => {
if (err) {
if (err.code === Status.ALREADY_EXISTS) {
resolve(new CreateCache.AlreadyExists());
this.clientWrapper
.getClient()
.CreateCache(
request,
{interceptors: this.interceptors},
(err, _resp) => {
if (err) {
if (err.code === Status.ALREADY_EXISTS) {
resolve(new CreateCache.AlreadyExists());
} else {
resolve(new CreateCache.Error(cacheServiceErrorMapper(err)));
}
} else {
resolve(new CreateCache.Error(cacheServiceErrorMapper(err)));
resolve(new CreateCache.Success());
}
} else {
resolve(new CreateCache.Success());
}
}
);
);
});
}

Expand All @@ -111,20 +112,21 @@ export class CacheControlClient {
const request = new grpcControl._DeleteCacheRequest({
cache_name: name,
});
this.logger.info(`Deleting cache: ${name}`);
this.logger.debug(`Deleting cache: ${name}`);
return await new Promise<DeleteCache.Response>(resolve => {
this.clientWrapper.getClient().DeleteCache(
request,
{interceptors: this.interceptors},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
(err, resp) => {
if (err) {
resolve(new DeleteCache.Error(cacheServiceErrorMapper(err)));
} else {
resolve(new DeleteCache.Success());
this.clientWrapper
.getClient()
.DeleteCache(
request,
{interceptors: this.interceptors},
(err, _resp) => {
if (err) {
resolve(new DeleteCache.Error(cacheServiceErrorMapper(err)));
} else {
resolve(new DeleteCache.Success());
}
}
}
);
);
});
}

Expand All @@ -134,7 +136,7 @@ export class CacheControlClient {
} catch (err) {
return new CacheFlush.Error(normalizeSdkError(err as Error));
}
this.logger.trace(`Flushing cache: ${cacheName}`);
this.logger.debug(`Flushing cache: ${cacheName}`);
return await this.sendFlushCache(cacheName);
}

Expand Down
13 changes: 11 additions & 2 deletions packages/client-sdk-web/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,16 @@
// async without await is often an error and in other uses it obfuscates
// the intent of the developer. Functions are async when they want to await.
"require-await": "error",
"import/no-duplicates": "error"
"import/no-duplicates": "error",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_"
}
]
},
"settings": {
"import/resolver": {
Expand All @@ -56,4 +65,4 @@
}
}
}
}
}
11 changes: 4 additions & 7 deletions packages/client-sdk-web/src/internal/cache-control-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,15 @@ export class CacheControlClient<
} catch (err) {
return new CreateCache.Error(normalizeSdkError(err as Error));
}
this.logger.info(`Creating cache: ${name}`);
this.logger.debug(`Creating cache: ${name}`);
const request = new _CreateCacheRequest();
request.setCacheName(name);

return await new Promise<CreateCache.Response>(resolve => {
this.clientWrapper.createCache(
request,
this.clientMetadataProvider.createClientMetadata(),
// eslint-disable-next-line @typescript-eslint/no-unused-vars
(err, resp) => {
(err, _resp) => {
if (err) {
if (err.code === StatusCode.ALREADY_EXISTS) {
resolve(new CreateCache.AlreadyExists());
Expand All @@ -102,13 +101,12 @@ export class CacheControlClient<
}
const request = new _DeleteCacheRequest();
request.setCacheName(name);
this.logger.info(`Deleting cache: ${name}`);
this.logger.debug(`Deleting cache: ${name}`);
return await new Promise<DeleteCache.Response>(resolve => {
this.clientWrapper.deleteCache(
request,
this.clientMetadataProvider.createClientMetadata(),
// eslint-disable-next-line @typescript-eslint/no-unused-vars
(err, resp) => {
(err, _resp) => {
if (err) {
resolve(new DeleteCache.Error(cacheServiceErrorMapper(err)));
} else {
Expand Down Expand Up @@ -138,7 +136,6 @@ export class CacheControlClient<
this.clientWrapper.flushCache(
request,
this.clientMetadataProvider.createClientMetadata(),
// eslint-disable-next-line @typescript-eslint/no-unused-vars
(err, resp) => {
if (resp) {
resolve(new CacheFlush.Success());
Expand Down
13 changes: 11 additions & 2 deletions packages/common-integration-tests/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,16 @@
// async without await is often an error and in other uses it obfuscates
// the intent of the developer. Functions are async when they want to await.
"require-await": "error",
"import/no-duplicates": "error"
"import/no-duplicates": "error",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_"
}
]
},
"settings": {
"import/resolver": {
Expand All @@ -56,4 +65,4 @@
}
}
}
}
}
13 changes: 11 additions & 2 deletions packages/core/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,16 @@
// async without await is often an error and in other uses it obfuscates
// the intent of the developer. Functions are async when they want to await.
"require-await": "error",
"import/no-duplicates": "error"
"import/no-duplicates": "error",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_"
}
]
},
"settings": {
"import/resolver": {
Expand All @@ -56,4 +65,4 @@
}
}
}
}
}

0 comments on commit 2604892

Please sign in to comment.