Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dynamic token refresh and authentication error handling #911

Merged
merged 18 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@
"@bufbuild/buf": "^1.28.1",
"@bufbuild/protoc-gen-es": "^1.6.0",
"@connectrpc/protoc-gen-connect-es": "^1.4.0",
"@types/express": "^4.17.21",
"@types/google-protobuf": "^3.15.5",
"@types/long": "^4.0.1",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"@vitest/coverage-istanbul": "^0.34.5",
"@vitest/coverage-v8": "^0.34.5",
"axios": "^1.7.7",
"eslint-plugin-tsdoc": "^0.2.16",
"express": "^4.21.1",
"prettier": "^2.7.1",
"ts-node": "^10.9.1",
"typedoc": "^0.25.13",
Expand All @@ -61,7 +64,7 @@
"vite": "^5.0.12",
"vite-plugin-commonjs": "^0.10.1",
"vite-plugin-dts": "^3.9.1",
"vite-tsconfig-paths": "^4.2.1",
"vite-tsconfig-paths": "^4.3.1",
"vitest": "^0.34.5"
},
"dependencies": {
Expand Down
25 changes: 17 additions & 8 deletions packages/sdk/src/api/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -804,19 +804,28 @@ 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.
export function errorMetadataOf(error: ConnectError): Record<string, string> {
if (!(error instanceof ConnectError)) {
return {};
}

// NOTE(chacha912): Currently, we only use the first detail to represent the
// error metadata.
const infos = error.findDetails(ErrorInfo);
for (const info of infos) {
if (info.metadata.code) {
return info.metadata.code;
}
return info.metadata;
}

return '';
return {};
}

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

/**
Expand Down
Loading
Loading