Skip to content

Commit

Permalink
chore(nice-grpc-web): fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aikoven committed Oct 14, 2023
1 parent de41157 commit 629ed12
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/nice-grpc-web/karma.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ export default (config: Config & Record<string, unknown>) => {
karmaTypescriptConfig: {
tsconfig: 'tsconfig.json',
compilerOptions: {
target: 'ES2015',
lib: ['ES2015', 'DOM', 'DOM.Iterable'],
target: 'ES2018',
lib: ['ES2018', 'DOM', 'DOM.Iterable'],
},
bundlerOptions: {
constants: {
Expand Down
2 changes: 1 addition & 1 deletion packages/nice-grpc-web/src/__tests__/unary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ const environment = detect();
new ClientError(
'/nice_grpc.test.Test2/TestUnary',
Status.UNIMPLEMENTED,
'[object Object]', // this is a bug in grpc-js
'The server does not implement the method /nice_grpc.test.Test2/TestUnary',
),
);
});
Expand Down
25 changes: 13 additions & 12 deletions packages/nice-grpc-web/src/client/makeCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ export async function* makeCall<Request, Response>(

try {
yield* response;

if (status != null && status !== Status.OK) {
throw new ClientError(definition.path, status, message ?? '');
}

if (status == null) {
throw new ClientError(
definition.path,
Status.UNKNOWN,
'Response stream closed without gRPC status',
);
}
} catch (err) {
if (requestError !== undefined) {
throw requestError.err;
Expand All @@ -135,17 +147,6 @@ export async function* makeCall<Request, Response>(
} finally {
finished = true;
signal.removeEventListener('abort', abortListener);

if (status != null && status !== Status.OK) {
throw new ClientError(definition.path, status, message ?? '');
}
}

if (status == null) {
throw new ClientError(
definition.path,
Status.UNKNOWN,
'Response stream closed without gRPC status',
);
innerAbortController.abort();
}
}

0 comments on commit 629ed12

Please sign in to comment.