From dbda92064f3fca42bba45771fd2939ccbcefaefd Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Thu, 1 Dec 2016 10:30:35 -0800 Subject: [PATCH] Also propagate serialization errors in unary server responses --- src/node/src/server.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/node/src/server.js b/src/node/src/server.js index bd0a5122ad0..51bb99ee537 100644 --- a/src/node/src/server.js +++ b/src/node/src/server.js @@ -127,7 +127,13 @@ function sendUnaryResponse(call, value, serialize, metadata, flags) { (new Metadata())._getCoreRepresentation(); call.metadataSent = true; } - var message = serialize(value); + var message; + try { + message = serialize(value); + } catch (e) { + e.code = grpc.status.INTERNAL; + handleError(e); + } message.grpcWriteFlags = flags; end_batch[grpc.opType.SEND_MESSAGE] = message; end_batch[grpc.opType.SEND_STATUS_FROM_SERVER] = status; @@ -282,7 +288,9 @@ function _write(chunk, encoding, callback) { try { message = this.serialize(chunk); } catch (e) { + e.code = grpc.status.INTERNAL; callback(e); + return; } if (_.isFinite(encoding)) { /* Attach the encoding if it is a finite number. This is the closest we