From 8d6f094db71a24c26a6dda6bf425949e25399af6 Mon Sep 17 00:00:00 2001 From: Colin King Date: Sat, 22 Sep 2018 11:32:36 -0700 Subject: [PATCH 1/2] Make ServiceError optionally null --- .../proto/examplecom/simple_service_pb_service.d.ts | 8 ++++---- examples/generated/proto/orphan_pb_service.d.ts | 4 ++-- src/service/grpcweb.ts | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/generated/proto/examplecom/simple_service_pb_service.d.ts b/examples/generated/proto/examplecom/simple_service_pb_service.d.ts index cf7f30c8..4c48a3e7 100644 --- a/examples/generated/proto/examplecom/simple_service_pb_service.d.ts +++ b/examples/generated/proto/examplecom/simple_service_pb_service.d.ts @@ -93,11 +93,11 @@ export class SimpleServiceClient { doUnary( requestMessage: proto_examplecom_simple_service_pb.UnaryRequest, metadata: grpc.Metadata, - callback: (error: ServiceError, responseMessage: proto_othercom_external_child_message_pb.ExternalChildMessage|null) => void + callback: (error: ServiceError|null, responseMessage: proto_othercom_external_child_message_pb.ExternalChildMessage|null) => void ): void; doUnary( requestMessage: proto_examplecom_simple_service_pb.UnaryRequest, - callback: (error: ServiceError, responseMessage: proto_othercom_external_child_message_pb.ExternalChildMessage|null) => void + callback: (error: ServiceError|null, responseMessage: proto_othercom_external_child_message_pb.ExternalChildMessage|null) => void ): void; doServerStream(requestMessage: proto_examplecom_simple_service_pb.StreamRequest, metadata?: grpc.Metadata): ResponseStream; doClientStream(metadata?: grpc.Metadata): RequestStream; @@ -105,11 +105,11 @@ export class SimpleServiceClient { delete( requestMessage: proto_examplecom_simple_service_pb.UnaryRequest, metadata: grpc.Metadata, - callback: (error: ServiceError, responseMessage: proto_examplecom_simple_service_pb.UnaryResponse|null) => void + callback: (error: ServiceError|null, responseMessage: proto_examplecom_simple_service_pb.UnaryResponse|null) => void ): void; delete( requestMessage: proto_examplecom_simple_service_pb.UnaryRequest, - callback: (error: ServiceError, responseMessage: proto_examplecom_simple_service_pb.UnaryResponse|null) => void + callback: (error: ServiceError|null, responseMessage: proto_examplecom_simple_service_pb.UnaryResponse|null) => void ): void; } diff --git a/examples/generated/proto/orphan_pb_service.d.ts b/examples/generated/proto/orphan_pb_service.d.ts index de676141..eb66da46 100644 --- a/examples/generated/proto/orphan_pb_service.d.ts +++ b/examples/generated/proto/orphan_pb_service.d.ts @@ -61,11 +61,11 @@ export class OrphanServiceClient { doUnary( requestMessage: proto_orphan_pb.OrphanUnaryRequest, metadata: grpc.Metadata, - callback: (error: ServiceError, responseMessage: proto_orphan_pb.OrphanMessage|null) => void + callback: (error: ServiceError|null, responseMessage: proto_orphan_pb.OrphanMessage|null) => void ): void; doUnary( requestMessage: proto_orphan_pb.OrphanUnaryRequest, - callback: (error: ServiceError, responseMessage: proto_orphan_pb.OrphanMessage|null) => void + callback: (error: ServiceError|null, responseMessage: proto_orphan_pb.OrphanMessage|null) => void ): void; doStream(requestMessage: proto_orphan_pb.OrphanStreamRequest, metadata?: grpc.Metadata): ResponseStream; } diff --git a/src/service/grpcweb.ts b/src/service/grpcweb.ts index d79b1af8..baa49256 100644 --- a/src/service/grpcweb.ts +++ b/src/service/grpcweb.ts @@ -509,11 +509,11 @@ function printUnaryStubMethodTypes(printer: CodePrinter, method: RPCMethodDescri .printLn(`${method.nameAsCamelCase}(`) .indent().printLn(`requestMessage: ${method.requestType},`) .printLn(`metadata: grpc.Metadata,`) - .printLn(`callback: (error: ServiceError, responseMessage: ${method.responseType}|null) => void`) + .printLn(`callback: (error: ServiceError|null, responseMessage: ${method.responseType}|null) => void`) .dedent().printLn(`): void;`) .printLn(`${method.nameAsCamelCase}(`) .indent().printLn(`requestMessage: ${method.requestType},`) - .printLn(`callback: (error: ServiceError, responseMessage: ${method.responseType}|null) => void`) + .printLn(`callback: (error: ServiceError|null, responseMessage: ${method.responseType}|null) => void`) .dedent().printLn(`): void;`); } From e642cf035ad73bee6200fba81089371b5be4ee59 Mon Sep 17 00:00:00 2001 From: Colin King Date: Sun, 23 Sep 2018 10:00:19 -0700 Subject: [PATCH 2/2] Unwrap optional error in tests --- test/integration/service/grpcweb.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/integration/service/grpcweb.ts b/test/integration/service/grpcweb.ts index 235474c9..6faedc33 100644 --- a/test/integration/service/grpcweb.ts +++ b/test/integration/service/grpcweb.ts @@ -166,9 +166,9 @@ describe("service/grpc-web", () => { assert.ok(error !== null && typeof error === "object", "should yield an error"); assert.ok(response === null, "should yield null instead of a response"); - assert.equal(error.message, "some internal error", "should expose the grpc error message (.message)"); - assert.equal(error.code, 13, "should expose the grpc status code (.code)"); - assert.ok(error.metadata instanceof grpc.Metadata, "should expose the trailing response metadata (.metadata)"); + assert.equal(error!.message, "some internal error", "should expose the grpc error message (.message)"); + assert.equal(error!.code, 13, "should expose the grpc status code (.code)"); + assert.ok(error!.metadata instanceof grpc.Metadata, "should expose the trailing response metadata (.metadata)"); done(); }); });