From f6b8045dd5b322defdb17cfad84bd8c5c5a1cba0 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 15 Aug 2019 15:22:53 +0100 Subject: [PATCH] send client error if it exists --- client/rpc_codec.go | 1 + server/rpc_stream.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/client/rpc_codec.go b/client/rpc_codec.go index 6ff84a64..93ed9fbf 100644 --- a/client/rpc_codec.go +++ b/client/rpc_codec.go @@ -126,6 +126,7 @@ func setHeaders(m *codec.Message) { set("Micro-Service", m.Target) set("Micro-Method", m.Method) set("Micro-Endpoint", m.Endpoint) + set("Micro-Error", m.Error) } // setupProtocol sets up the old protocol diff --git a/server/rpc_stream.go b/server/rpc_stream.go index 185f1ff9..a4e64af8 100644 --- a/server/rpc_stream.go +++ b/server/rpc_stream.go @@ -2,6 +2,8 @@ package server import ( "context" + "errors" + "io" "sync" "github.com/micro/go-micro/codec" @@ -59,6 +61,20 @@ func (r *rpcStream) Recv(msg interface{}) error { return err } + // check the error + if len(req.Error) > 0 { + // Check the client closed the stream + switch req.Error { + case lastStreamResponseError.Error(): + // discard body + r.codec.ReadBody(nil) + r.err = io.EOF + return io.EOF + default: + return errors.New(req.Error) + } + } + // we need to stay up to date with sequence numbers r.id = req.Id if err := r.codec.ReadBody(msg); err != nil {