From 4010144a9fb9d5d90f1356a5449d2b8eb5d2e271 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Tue, 18 May 2021 10:30:01 +0200 Subject: [PATCH] Throw error object on HTTP error Fixes #15 --- generator/template.go | 5 +- integration_tests/integration_test.ts | 10 ++ integration_tests/service.go | 6 + integration_tests/service.pb.go | 182 ++++++++++++++++---------- integration_tests/service.pb.gw.go | 81 ++++++++++++ integration_tests/service.proto | 1 + 6 files changed, 214 insertions(+), 71 deletions(-) diff --git a/generator/template.go b/generator/template.go index bf02c98..e0e5286 100644 --- a/generator/template.go +++ b/generator/template.go @@ -99,7 +99,10 @@ export function fetchReq(path: string, init?: InitReq): Promise { const url = pathPrefix ? ` + "`${pathPrefix}${path}`" + ` : path - return fetch(url, req).then(r => r.json()) as Promise + return fetch(url, req).then(r => r.json().then((body: O) => { + if (!r.ok) { throw body; } + return body; + })) as Promise } // NotifyStreamEntityArrival is a callback that will be called on streaming entity arrival diff --git a/integration_tests/integration_test.ts b/integration_tests/integration_test.ts index abf348c..7547e82 100644 --- a/integration_tests/integration_test.ts +++ b/integration_tests/integration_test.ts @@ -19,6 +19,16 @@ describe("test grpc-gateway-ts communication", () => { expect(result.result).to.equal(200) }) + it("failing unary request", async () => { + try { + await CounterService.FailingIncrement({ counter: 199 }, { pathPrefix: "http://localhost:8081" }); + expect.fail("expected call to throw"); + } catch (e) { + expect(e).to.have.property("message", "this increment does not work") + expect(e).to.have.property("code", 14); + } + }) + it('streaming request', async () => { const response = [] as number[] await CounterService.StreamingIncrements({ counter: 1 }, (resp) => response.push(resp.result), { pathPrefix: "http://localhost:8081" }) diff --git a/integration_tests/service.go b/integration_tests/service.go index 1e0649d..cffdbe5 100644 --- a/integration_tests/service.go +++ b/integration_tests/service.go @@ -4,6 +4,8 @@ import ( "context" "time" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" "google.golang.org/protobuf/types/known/emptypb" ) @@ -21,6 +23,10 @@ func (r *RealCounterService) Increment(c context.Context, req *UnaryRequest) (*U }, nil } +func (r *RealCounterService) FailingIncrement(c context.Context, req *UnaryRequest) (*UnaryResponse, error) { + return nil, status.Errorf(codes.Unavailable, "this increment does not work") +} + func (r *RealCounterService) StreamingIncrements(req *StreamingRequest, service CounterService_StreamingIncrementsServer) error { times := 5 counter := req.Counter diff --git a/integration_tests/service.pb.go b/integration_tests/service.pb.go index cb3894e..276b14e 100644 --- a/integration_tests/service.pb.go +++ b/integration_tests/service.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.25.0 -// protoc v3.15.6 +// protoc v3.15.8 // source: service.proto package main @@ -1006,7 +1006,7 @@ var file_service_proto_rawDesc = []byte{ 0x09, 0x52, 0x01, 0x62, 0x12, 0x38, 0x0a, 0x0e, 0x7a, 0x65, 0x72, 0x6f, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x5a, 0x65, 0x72, 0x6f, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x4d, 0x73, 0x67, - 0x52, 0x0c, 0x7a, 0x65, 0x72, 0x6f, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x4d, 0x73, 0x67, 0x32, 0xbb, + 0x52, 0x0c, 0x7a, 0x65, 0x72, 0x6f, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x4d, 0x73, 0x67, 0x32, 0xf8, 0x07, 0x0a, 0x0e, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x34, 0x0a, 0x09, 0x49, 0x6e, 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x12, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x55, 0x6e, 0x61, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, @@ -1016,58 +1016,62 @@ var file_service_proto_rawDesc = []byte{ 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, - 0x01, 0x12, 0x56, 0x0a, 0x07, 0x48, 0x54, 0x54, 0x50, 0x47, 0x65, 0x74, 0x12, 0x14, 0x2e, 0x6d, - 0x61, 0x69, 0x6e, 0x2e, 0x48, 0x74, 0x74, 0x70, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x48, 0x74, 0x74, 0x70, 0x47, 0x65, - 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1e, 0x82, 0xd3, 0xe4, 0x93, 0x02, - 0x18, 0x12, 0x16, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x7b, 0x6e, 0x75, 0x6d, 0x5f, 0x74, 0x6f, 0x5f, - 0x69, 0x6e, 0x63, 0x72, 0x65, 0x61, 0x73, 0x65, 0x7d, 0x12, 0x63, 0x0a, 0x1a, 0x48, 0x54, 0x54, - 0x50, 0x50, 0x6f, 0x73, 0x74, 0x57, 0x69, 0x74, 0x68, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x42, + 0x01, 0x12, 0x3b, 0x0a, 0x10, 0x46, 0x61, 0x69, 0x6c, 0x69, 0x6e, 0x67, 0x49, 0x6e, 0x63, 0x72, + 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x12, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x55, 0x6e, 0x61, + 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x6d, 0x61, 0x69, 0x6e, + 0x2e, 0x55, 0x6e, 0x61, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x56, + 0x0a, 0x07, 0x48, 0x54, 0x54, 0x50, 0x47, 0x65, 0x74, 0x12, 0x14, 0x2e, 0x6d, 0x61, 0x69, 0x6e, + 0x2e, 0x48, 0x74, 0x74, 0x70, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x15, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x48, 0x74, 0x74, 0x70, 0x47, 0x65, 0x74, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1e, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x18, 0x12, 0x16, + 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x7b, 0x6e, 0x75, 0x6d, 0x5f, 0x74, 0x6f, 0x5f, 0x69, 0x6e, 0x63, + 0x72, 0x65, 0x61, 0x73, 0x65, 0x7d, 0x12, 0x63, 0x0a, 0x1a, 0x48, 0x54, 0x54, 0x50, 0x50, 0x6f, + 0x73, 0x74, 0x57, 0x69, 0x74, 0x68, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x42, 0x6f, 0x64, 0x79, + 0x50, 0x61, 0x74, 0x68, 0x12, 0x15, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x48, 0x74, 0x74, 0x70, + 0x50, 0x6f, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x6d, 0x61, + 0x69, 0x6e, 0x2e, 0x48, 0x74, 0x74, 0x70, 0x50, 0x6f, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x22, 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x22, 0x09, 0x2f, 0x70, 0x6f, + 0x73, 0x74, 0x2f, 0x7b, 0x61, 0x7d, 0x3a, 0x03, 0x72, 0x65, 0x71, 0x12, 0x63, 0x0a, 0x18, 0x48, + 0x54, 0x54, 0x50, 0x50, 0x6f, 0x73, 0x74, 0x57, 0x69, 0x74, 0x68, 0x53, 0x74, 0x61, 0x72, 0x42, 0x6f, 0x64, 0x79, 0x50, 0x61, 0x74, 0x68, 0x12, 0x15, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x48, 0x74, 0x74, 0x70, 0x50, 0x6f, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x48, 0x74, 0x74, 0x70, 0x50, 0x6f, 0x73, 0x74, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x22, 0x09, - 0x2f, 0x70, 0x6f, 0x73, 0x74, 0x2f, 0x7b, 0x61, 0x7d, 0x3a, 0x03, 0x72, 0x65, 0x71, 0x12, 0x63, - 0x0a, 0x18, 0x48, 0x54, 0x54, 0x50, 0x50, 0x6f, 0x73, 0x74, 0x57, 0x69, 0x74, 0x68, 0x53, 0x74, - 0x61, 0x72, 0x42, 0x6f, 0x64, 0x79, 0x50, 0x61, 0x74, 0x68, 0x12, 0x15, 0x2e, 0x6d, 0x61, 0x69, - 0x6e, 0x2e, 0x48, 0x74, 0x74, 0x70, 0x50, 0x6f, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x16, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x48, 0x74, 0x74, 0x70, 0x50, 0x6f, 0x73, - 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x18, 0x82, 0xd3, 0xe4, 0x93, 0x02, - 0x12, 0x22, 0x0d, 0x2f, 0x70, 0x6f, 0x73, 0x74, 0x2f, 0x7b, 0x61, 0x7d, 0x2f, 0x7b, 0x63, 0x7d, - 0x3a, 0x01, 0x2a, 0x12, 0x4f, 0x0a, 0x09, 0x48, 0x54, 0x54, 0x50, 0x50, 0x61, 0x74, 0x63, 0x68, - 0x12, 0x16, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x48, 0x74, 0x74, 0x70, 0x50, 0x61, 0x74, 0x63, - 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, - 0x48, 0x74, 0x74, 0x70, 0x50, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x22, 0x11, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0b, 0x32, 0x06, 0x2f, 0x70, 0x61, 0x74, 0x63, - 0x68, 0x3a, 0x01, 0x2a, 0x12, 0x52, 0x0a, 0x0a, 0x48, 0x54, 0x54, 0x50, 0x44, 0x65, 0x6c, 0x65, - 0x74, 0x65, 0x12, 0x17, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x48, 0x74, 0x74, 0x70, 0x44, 0x65, - 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, - 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, - 0x70, 0x74, 0x79, 0x22, 0x13, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0d, 0x2a, 0x0b, 0x2f, 0x64, 0x65, - 0x6c, 0x65, 0x74, 0x65, 0x2f, 0x7b, 0x61, 0x7d, 0x12, 0x36, 0x0a, 0x0f, 0x45, 0x78, 0x74, 0x65, - 0x72, 0x6e, 0x61, 0x6c, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x10, 0x2e, 0x45, 0x78, - 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, - 0x45, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x12, 0x87, 0x01, 0x0a, 0x1a, 0x48, 0x54, 0x54, 0x50, 0x47, 0x65, 0x74, 0x57, 0x69, 0x74, 0x68, - 0x55, 0x52, 0x4c, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, - 0x27, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x47, 0x65, 0x74, 0x57, 0x69, - 0x74, 0x68, 0x55, 0x52, 0x4c, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x50, 0x61, 0x72, 0x61, 0x6d, - 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x28, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, - 0x48, 0x54, 0x54, 0x50, 0x47, 0x65, 0x74, 0x57, 0x69, 0x74, 0x68, 0x55, 0x52, 0x4c, 0x53, 0x65, - 0x61, 0x72, 0x63, 0x68, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x22, 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x12, 0x0e, 0x2f, 0x61, 0x70, 0x69, - 0x2f, 0x71, 0x75, 0x65, 0x72, 0x79, 0x2f, 0x7b, 0x61, 0x7d, 0x12, 0x9f, 0x01, 0x0a, 0x23, 0x48, - 0x54, 0x54, 0x50, 0x47, 0x65, 0x74, 0x57, 0x69, 0x74, 0x68, 0x5a, 0x65, 0x72, 0x6f, 0x56, 0x61, - 0x6c, 0x75, 0x65, 0x55, 0x52, 0x4c, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x50, 0x61, 0x72, 0x61, - 0x6d, 0x73, 0x12, 0x30, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x47, 0x65, - 0x74, 0x57, 0x69, 0x74, 0x68, 0x5a, 0x65, 0x72, 0x6f, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x55, 0x52, - 0x4c, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x31, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x48, 0x54, 0x54, 0x50, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x18, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x12, 0x22, 0x0d, + 0x2f, 0x70, 0x6f, 0x73, 0x74, 0x2f, 0x7b, 0x61, 0x7d, 0x2f, 0x7b, 0x63, 0x7d, 0x3a, 0x01, 0x2a, + 0x12, 0x4f, 0x0a, 0x09, 0x48, 0x54, 0x54, 0x50, 0x50, 0x61, 0x74, 0x63, 0x68, 0x12, 0x16, 0x2e, + 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x48, 0x74, 0x74, 0x70, 0x50, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x48, 0x74, 0x74, + 0x70, 0x50, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x11, + 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0b, 0x32, 0x06, 0x2f, 0x70, 0x61, 0x74, 0x63, 0x68, 0x3a, 0x01, + 0x2a, 0x12, 0x52, 0x0a, 0x0a, 0x48, 0x54, 0x54, 0x50, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, + 0x17, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x48, 0x74, 0x74, 0x70, 0x44, 0x65, 0x6c, 0x65, 0x74, + 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, + 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, + 0x22, 0x13, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0d, 0x2a, 0x0b, 0x2f, 0x64, 0x65, 0x6c, 0x65, 0x74, + 0x65, 0x2f, 0x7b, 0x61, 0x7d, 0x12, 0x36, 0x0a, 0x0f, 0x45, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, + 0x6c, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x10, 0x2e, 0x45, 0x78, 0x74, 0x65, 0x72, + 0x6e, 0x61, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x45, 0x78, 0x74, + 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x87, 0x01, + 0x0a, 0x1a, 0x48, 0x54, 0x54, 0x50, 0x47, 0x65, 0x74, 0x57, 0x69, 0x74, 0x68, 0x55, 0x52, 0x4c, + 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x27, 0x2e, 0x6d, + 0x61, 0x69, 0x6e, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x47, 0x65, 0x74, 0x57, 0x69, 0x74, 0x68, 0x55, + 0x52, 0x4c, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x28, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x48, 0x54, 0x54, + 0x50, 0x47, 0x65, 0x74, 0x57, 0x69, 0x74, 0x68, 0x55, 0x52, 0x4c, 0x53, 0x65, 0x61, 0x72, 0x63, + 0x68, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x12, 0x0e, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x71, 0x75, + 0x65, 0x72, 0x79, 0x2f, 0x7b, 0x61, 0x7d, 0x12, 0x9f, 0x01, 0x0a, 0x23, 0x48, 0x54, 0x54, 0x50, 0x47, 0x65, 0x74, 0x57, 0x69, 0x74, 0x68, 0x5a, 0x65, 0x72, 0x6f, 0x56, 0x61, 0x6c, 0x75, 0x65, - 0x55, 0x52, 0x4c, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x13, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0d, 0x12, - 0x0b, 0x2f, 0x70, 0x61, 0x74, 0x68, 0x2f, 0x71, 0x75, 0x65, 0x72, 0x79, 0x42, 0x09, 0x5a, 0x07, - 0x2e, 0x2f, 0x3b, 0x6d, 0x61, 0x69, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x55, 0x52, 0x4c, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, + 0x30, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x47, 0x65, 0x74, 0x57, 0x69, + 0x74, 0x68, 0x5a, 0x65, 0x72, 0x6f, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x55, 0x52, 0x4c, 0x53, 0x65, + 0x61, 0x72, 0x63, 0x68, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x31, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x47, 0x65, 0x74, + 0x57, 0x69, 0x74, 0x68, 0x5a, 0x65, 0x72, 0x6f, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x55, 0x52, 0x4c, + 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x13, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0d, 0x12, 0x0b, 0x2f, 0x70, + 0x61, 0x74, 0x68, 0x2f, 0x71, 0x75, 0x65, 0x72, 0x79, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x2f, 0x3b, + 0x6d, 0x61, 0x69, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1114,26 +1118,28 @@ var file_service_proto_depIdxs = []int32{ 14, // 4: main.HTTPGetWithZeroValueURLSearchParamsResponse.zero_value_msg:type_name -> main.ZeroValueMsg 0, // 5: main.CounterService.Increment:input_type -> main.UnaryRequest 2, // 6: main.CounterService.StreamingIncrements:input_type -> main.StreamingRequest - 4, // 7: main.CounterService.HTTPGet:input_type -> main.HttpGetRequest - 6, // 8: main.CounterService.HTTPPostWithNestedBodyPath:input_type -> main.HttpPostRequest - 6, // 9: main.CounterService.HTTPPostWithStarBodyPath:input_type -> main.HttpPostRequest - 9, // 10: main.CounterService.HTTPPatch:input_type -> main.HttpPatchRequest - 11, // 11: main.CounterService.HTTPDelete:input_type -> main.HttpDeleteRequest - 18, // 12: main.CounterService.ExternalMessage:input_type -> ExternalRequest - 12, // 13: main.CounterService.HTTPGetWithURLSearchParams:input_type -> main.HTTPGetWithURLSearchParamsRequest - 15, // 14: main.CounterService.HTTPGetWithZeroValueURLSearchParams:input_type -> main.HTTPGetWithZeroValueURLSearchParamsRequest - 1, // 15: main.CounterService.Increment:output_type -> main.UnaryResponse - 3, // 16: main.CounterService.StreamingIncrements:output_type -> main.StreamingResponse - 5, // 17: main.CounterService.HTTPGet:output_type -> main.HttpGetResponse - 8, // 18: main.CounterService.HTTPPostWithNestedBodyPath:output_type -> main.HttpPostResponse - 8, // 19: main.CounterService.HTTPPostWithStarBodyPath:output_type -> main.HttpPostResponse - 10, // 20: main.CounterService.HTTPPatch:output_type -> main.HttpPatchResponse - 19, // 21: main.CounterService.HTTPDelete:output_type -> google.protobuf.Empty - 20, // 22: main.CounterService.ExternalMessage:output_type -> ExternalResponse - 13, // 23: main.CounterService.HTTPGetWithURLSearchParams:output_type -> main.HTTPGetWithURLSearchParamsResponse - 16, // 24: main.CounterService.HTTPGetWithZeroValueURLSearchParams:output_type -> main.HTTPGetWithZeroValueURLSearchParamsResponse - 15, // [15:25] is the sub-list for method output_type - 5, // [5:15] is the sub-list for method input_type + 0, // 7: main.CounterService.FailingIncrement:input_type -> main.UnaryRequest + 4, // 8: main.CounterService.HTTPGet:input_type -> main.HttpGetRequest + 6, // 9: main.CounterService.HTTPPostWithNestedBodyPath:input_type -> main.HttpPostRequest + 6, // 10: main.CounterService.HTTPPostWithStarBodyPath:input_type -> main.HttpPostRequest + 9, // 11: main.CounterService.HTTPPatch:input_type -> main.HttpPatchRequest + 11, // 12: main.CounterService.HTTPDelete:input_type -> main.HttpDeleteRequest + 18, // 13: main.CounterService.ExternalMessage:input_type -> ExternalRequest + 12, // 14: main.CounterService.HTTPGetWithURLSearchParams:input_type -> main.HTTPGetWithURLSearchParamsRequest + 15, // 15: main.CounterService.HTTPGetWithZeroValueURLSearchParams:input_type -> main.HTTPGetWithZeroValueURLSearchParamsRequest + 1, // 16: main.CounterService.Increment:output_type -> main.UnaryResponse + 3, // 17: main.CounterService.StreamingIncrements:output_type -> main.StreamingResponse + 1, // 18: main.CounterService.FailingIncrement:output_type -> main.UnaryResponse + 5, // 19: main.CounterService.HTTPGet:output_type -> main.HttpGetResponse + 8, // 20: main.CounterService.HTTPPostWithNestedBodyPath:output_type -> main.HttpPostResponse + 8, // 21: main.CounterService.HTTPPostWithStarBodyPath:output_type -> main.HttpPostResponse + 10, // 22: main.CounterService.HTTPPatch:output_type -> main.HttpPatchResponse + 19, // 23: main.CounterService.HTTPDelete:output_type -> google.protobuf.Empty + 20, // 24: main.CounterService.ExternalMessage:output_type -> ExternalResponse + 13, // 25: main.CounterService.HTTPGetWithURLSearchParams:output_type -> main.HTTPGetWithURLSearchParamsResponse + 16, // 26: main.CounterService.HTTPGetWithZeroValueURLSearchParams:output_type -> main.HTTPGetWithZeroValueURLSearchParamsResponse + 16, // [16:27] is the sub-list for method output_type + 5, // [5:16] is the sub-list for method input_type 5, // [5:5] is the sub-list for extension type_name 5, // [5:5] is the sub-list for extension extendee 0, // [0:5] is the sub-list for field type_name @@ -1385,6 +1391,7 @@ const _ = grpc.SupportPackageIsVersion6 type CounterServiceClient interface { Increment(ctx context.Context, in *UnaryRequest, opts ...grpc.CallOption) (*UnaryResponse, error) StreamingIncrements(ctx context.Context, in *StreamingRequest, opts ...grpc.CallOption) (CounterService_StreamingIncrementsClient, error) + FailingIncrement(ctx context.Context, in *UnaryRequest, opts ...grpc.CallOption) (*UnaryResponse, error) HTTPGet(ctx context.Context, in *HttpGetRequest, opts ...grpc.CallOption) (*HttpGetResponse, error) HTTPPostWithNestedBodyPath(ctx context.Context, in *HttpPostRequest, opts ...grpc.CallOption) (*HttpPostResponse, error) HTTPPostWithStarBodyPath(ctx context.Context, in *HttpPostRequest, opts ...grpc.CallOption) (*HttpPostResponse, error) @@ -1444,6 +1451,15 @@ func (x *counterServiceStreamingIncrementsClient) Recv() (*StreamingResponse, er return m, nil } +func (c *counterServiceClient) FailingIncrement(ctx context.Context, in *UnaryRequest, opts ...grpc.CallOption) (*UnaryResponse, error) { + out := new(UnaryResponse) + err := c.cc.Invoke(ctx, "/main.CounterService/FailingIncrement", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *counterServiceClient) HTTPGet(ctx context.Context, in *HttpGetRequest, opts ...grpc.CallOption) (*HttpGetResponse, error) { out := new(HttpGetResponse) err := c.cc.Invoke(ctx, "/main.CounterService/HTTPGet", in, out, opts...) @@ -1520,6 +1536,7 @@ func (c *counterServiceClient) HTTPGetWithZeroValueURLSearchParams(ctx context.C type CounterServiceServer interface { Increment(context.Context, *UnaryRequest) (*UnaryResponse, error) StreamingIncrements(*StreamingRequest, CounterService_StreamingIncrementsServer) error + FailingIncrement(context.Context, *UnaryRequest) (*UnaryResponse, error) HTTPGet(context.Context, *HttpGetRequest) (*HttpGetResponse, error) HTTPPostWithNestedBodyPath(context.Context, *HttpPostRequest) (*HttpPostResponse, error) HTTPPostWithStarBodyPath(context.Context, *HttpPostRequest) (*HttpPostResponse, error) @@ -1540,6 +1557,9 @@ func (*UnimplementedCounterServiceServer) Increment(context.Context, *UnaryReque func (*UnimplementedCounterServiceServer) StreamingIncrements(*StreamingRequest, CounterService_StreamingIncrementsServer) error { return status.Errorf(codes.Unimplemented, "method StreamingIncrements not implemented") } +func (*UnimplementedCounterServiceServer) FailingIncrement(context.Context, *UnaryRequest) (*UnaryResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method FailingIncrement not implemented") +} func (*UnimplementedCounterServiceServer) HTTPGet(context.Context, *HttpGetRequest) (*HttpGetResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method HTTPGet not implemented") } @@ -1608,6 +1628,24 @@ func (x *counterServiceStreamingIncrementsServer) Send(m *StreamingResponse) err return x.ServerStream.SendMsg(m) } +func _CounterService_FailingIncrement_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UnaryRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CounterServiceServer).FailingIncrement(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/main.CounterService/FailingIncrement", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CounterServiceServer).FailingIncrement(ctx, req.(*UnaryRequest)) + } + return interceptor(ctx, in, info, handler) +} + func _CounterService_HTTPGet_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(HttpGetRequest) if err := dec(in); err != nil { @@ -1760,6 +1798,10 @@ var _CounterService_serviceDesc = grpc.ServiceDesc{ MethodName: "Increment", Handler: _CounterService_Increment_Handler, }, + { + MethodName: "FailingIncrement", + Handler: _CounterService_FailingIncrement_Handler, + }, { MethodName: "HTTPGet", Handler: _CounterService_HTTPGet_Handler, diff --git a/integration_tests/service.pb.gw.go b/integration_tests/service.pb.gw.go index 1e0bb7a..c3ec24c 100644 --- a/integration_tests/service.pb.gw.go +++ b/integration_tests/service.pb.gw.go @@ -92,6 +92,40 @@ func request_CounterService_StreamingIncrements_0(ctx context.Context, marshaler } +func request_CounterService_FailingIncrement_0(ctx context.Context, marshaler runtime.Marshaler, client CounterServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq UnaryRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.FailingIncrement(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_CounterService_FailingIncrement_0(ctx context.Context, marshaler runtime.Marshaler, server CounterServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq UnaryRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.FailingIncrement(ctx, &protoReq) + return msg, metadata, err + +} + func request_CounterService_HTTPGet_0(ctx context.Context, marshaler runtime.Marshaler, client CounterServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq HttpGetRequest var metadata runtime.ServerMetadata @@ -592,6 +626,29 @@ func RegisterCounterServiceHandlerServer(ctx context.Context, mux *runtime.Serve return }) + mux.Handle("POST", pattern_CounterService_FailingIncrement_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_CounterService_FailingIncrement_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_CounterService_FailingIncrement_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + mux.Handle("GET", pattern_CounterService_HTTPGet_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -857,6 +914,26 @@ func RegisterCounterServiceHandlerClient(ctx context.Context, mux *runtime.Serve }) + mux.Handle("POST", pattern_CounterService_FailingIncrement_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_CounterService_FailingIncrement_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_CounterService_FailingIncrement_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + mux.Handle("GET", pattern_CounterService_HTTPGet_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -1025,6 +1102,8 @@ var ( pattern_CounterService_StreamingIncrements_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"main.CounterService", "StreamingIncrements"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_CounterService_FailingIncrement_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"main.CounterService", "FailingIncrement"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_CounterService_HTTPGet_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1}, []string{"api", "num_to_increase"}, "", runtime.AssumeColonVerbOpt(true))) pattern_CounterService_HTTPPostWithNestedBodyPath_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1}, []string{"post", "a"}, "", runtime.AssumeColonVerbOpt(true))) @@ -1047,6 +1126,8 @@ var ( forward_CounterService_StreamingIncrements_0 = runtime.ForwardResponseStream + forward_CounterService_FailingIncrement_0 = runtime.ForwardResponseMessage + forward_CounterService_HTTPGet_0 = runtime.ForwardResponseMessage forward_CounterService_HTTPPostWithNestedBodyPath_0 = runtime.ForwardResponseMessage diff --git a/integration_tests/service.proto b/integration_tests/service.proto index 6a30739..bb00c98 100644 --- a/integration_tests/service.proto +++ b/integration_tests/service.proto @@ -89,6 +89,7 @@ message HTTPGetWithZeroValueURLSearchParamsResponse { service CounterService { rpc Increment(UnaryRequest) returns (UnaryResponse); rpc StreamingIncrements(StreamingRequest) returns (stream StreamingResponse); + rpc FailingIncrement(UnaryRequest) returns (UnaryResponse); rpc HTTPGet(HttpGetRequest) returns (HttpGetResponse) { option (google.api.http) = { get: "/api/{num_to_increase}"