Skip to content

Commit c5bdd9c

Browse files
author
Cedric Kassen
committed
remove oversight asyncs and replace safeDeserializeMessage
1 parent 555643d commit c5bdd9c

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

packages/grpc-js/src/server-call.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ export class Http2ServerCallStream<
568568
this.stream.on('end', onEnd);
569569
this.stream.on('error', onEnd);
570570

571-
async function onData(chunk: Buffer) {
571+
function onData(chunk: Buffer) {
572572
receivedLength += chunk.byteLength;
573573

574574
if (limit !== -1 && receivedLength > limit) {
@@ -586,7 +586,7 @@ export class Http2ServerCallStream<
586586
body.push(chunk);
587587
}
588588

589-
async function onEnd(err?: Error) {
589+
function onEnd(err?: Error) {
590590
stream.removeListener('data', onData);
591591
stream.removeListener('end', onEnd);
592592
stream.removeListener('error', onEnd);
@@ -615,13 +615,19 @@ export class Http2ServerCallStream<
615615
);
616616

617617
if (Buffer.isBuffer(decompressedMessage)) {
618-
call.safeDeserializeMessage(decompressedMessage, resolve, reject);
618+
call
619+
.deserializeMessageWithInternalError(decompressedMessage)
620+
.then(resolve)
621+
.catch(reject);
619622
return;
620623
}
621624

622625
decompressedMessage.then(
623626
decompressed =>
624-
call.safeDeserializeMessage(decompressed, resolve, reject),
627+
call
628+
.deserializeMessageWithInternalError(decompressed)
629+
.then(resolve)
630+
.catch(reject),
625631
(err: any) =>
626632
reject(
627633
err.code
@@ -636,20 +642,14 @@ export class Http2ServerCallStream<
636642
});
637643
}
638644

639-
private safeDeserializeMessage(
640-
buffer: Buffer,
641-
resolve: (
642-
value: void | RequestType | PromiseLike<void | RequestType>
643-
) => void,
644-
reject: (reason: any) => void
645-
) {
645+
private async deserializeMessageWithInternalError(buffer: Buffer) {
646646
try {
647-
resolve(this.deserializeMessage(buffer));
647+
return this.deserializeMessage(buffer);
648648
} catch (err) {
649-
reject({
649+
throw {
650650
details: getErrorMessage(err),
651651
code: Status.INTERNAL,
652-
});
652+
};
653653
}
654654
}
655655

packages/grpc-js/src/server.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ function getUnimplementedStatusResponse(
9696
return {
9797
code: Status.UNIMPLEMENTED,
9898
details: `The server does not implement the method ${methodName}`,
99-
metadata: new Metadata(),
10099
};
101100
}
102101

0 commit comments

Comments
 (0)