From 07cd4de2f2614cc41894dcb69fe4f553768b95f1 Mon Sep 17 00:00:00 2001 From: Stephen J Day Date: Wed, 22 Nov 2017 12:06:18 -0800 Subject: [PATCH] ttrpc: correctly propagate error from response Signed-off-by: Stephen J Day --- README.md | 9 ++++++--- client.go | 12 +++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8f1bab7..6e2159a 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,9 @@ Very new. YMMV. TODO: -- [ ] Plumb error codes and GRPC status -- [ ] Remove use of any type and dependency on typeurl package -- [ ] Ensure that protocol can support streaming in the future +- [X] Plumb error codes and GRPC status +- [X] Remove use of any type and dependency on typeurl package +- [X] Ensure that protocol can support streaming in the future +- [ ] Document protocol layout +- [ ] Add testing under concurrent load to ensure +- [ ] Verify connection error handling diff --git a/client.go b/client.go index 265ce95..6f14d1e 100644 --- a/client.go +++ b/client.go @@ -7,6 +7,8 @@ import ( "sync/atomic" "github.com/gogo/protobuf/proto" + "github.com/pkg/errors" + "google.golang.org/grpc/status" ) type Client struct { @@ -58,7 +60,15 @@ func (c *Client) Call(ctx context.Context, service, method string, req, resp int return err } - return c.codec.Unmarshal(response.Payload, resp) + if err := c.codec.Unmarshal(response.Payload, resp); err != nil { + return err + } + + if response.Status == nil { + return errors.New("no status provided on response") + } + + return status.ErrorProto(response.Status) } func (c *Client) Close() error {