Skip to content

Commit 9913bda

Browse files
committed
feat(grpc): log call response errors
1 parent 2e84dcf commit 9913bda

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/grpc/GrpcServer.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,19 @@ class GrpcServer {
1919
constructor(private logger: Logger) {
2020
this.server = serverProxy(new grpc.Server());
2121

22-
this.server.use((ctx: any, next: any) => {
22+
this.server.use(async (ctx: any, next: any) => {
2323
logger.debug(`received call ${ctx.service.path}`);
24-
next();
24+
25+
await next();
26+
27+
const status = ctx.status || ctx.call.status;
28+
if (!status) {
29+
logger.debug(`unknown status for call ${ctx.service.path}`);
30+
} else if (status.code !== 0) {
31+
logger.error(`call ${ctx.service.path} errored with code ${status.details.code}: ${status.details.message}`);
32+
} else {
33+
logger.trace(`call ${ctx.service.path} succeeded`);
34+
}
2535
});
2636
}
2737

0 commit comments

Comments
 (0)