Skip to content

Commit

Permalink
Apply CodeRabbit review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
chacha912 committed Oct 24, 2024
1 parent 840cf00 commit 0cbdff2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 45 deletions.
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@bufbuild/buf": "^1.28.1",
"@bufbuild/protoc-gen-es": "^1.6.0",
"@connectrpc/protoc-gen-connect-es": "^1.4.0",
"@types/express": "^5.0.0",
"@types/express": "^4.17.21",
"@types/google-protobuf": "^3.15.5",
"@types/long": "^4.0.1",
"@typescript-eslint/eslint-plugin": "^6.21.0",
Expand Down
25 changes: 9 additions & 16 deletions packages/sdk/src/api/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -803,26 +803,12 @@ function toChangePack(pack: ChangePack<Indexable>): PbChangePack {
});
}

/**
* `errorCodeOf` returns the error code of the given connect error.
*/
export function errorCodeOf(error: ConnectError): string {
// NOTE(hackerwins): Currently, we only use the first detail to represent the
// error code.
const infos = error.findDetails(ErrorInfo);
for (const info of infos) {
if (info.metadata.code) {
return info.metadata.code;
}
}

return '';
}

/**
* `errorMetadataOf` returns the error code of the given connect error.
*/
export function errorMetadataOf(error: ConnectError): Record<string, string> {
// NOTE(chacha912): Currently, we only use the first detail to represent the
// error metadata.
const infos = error.findDetails(ErrorInfo);
for (const info of infos) {
return info.metadata;
Expand All @@ -831,6 +817,13 @@ export function errorMetadataOf(error: ConnectError): Record<string, string> {
return {};
}

/**
* `errorCodeOf` returns the error code of the given connect error.
*/
export function errorCodeOf(error: ConnectError): string {
return errorMetadataOf(error).code ?? '';
}

/**
* `fromChangeID` converts the given Protobuf format to model format.
*/
Expand Down
4 changes: 4 additions & 0 deletions packages/sdk/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,10 @@ export class Client {
],
}),
);
this.rpcClient.transport.interceptors = [
createAuthInterceptor(this.apiKey, token),
createMetricInterceptor(),
];
return true;
}

Expand Down
56 changes: 28 additions & 28 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0cbdff2

Please sign in to comment.