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 95f5faa
Show file tree
Hide file tree
Showing 3 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
29 changes: 13 additions & 16 deletions packages/sdk/src/api/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -804,25 +804,15 @@ function toChangePack(pack: ChangePack<Indexable>): PbChangePack {
}

/**
* `errorCodeOf` returns the error code of the given connect error.
* `errorMetadataOf` returns the error metadata 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;
}
export function errorMetadataOf(error: ConnectError): Record<string, string> {
if (!(error instanceof ConnectError)) {
return {};
}

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 +821,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
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 95f5faa

Please sign in to comment.