Merge pull request #1173 from lyuxuan/fix_status_return
add error handling for InvalidArgument error from sendResponse()
This commit is contained in:
22
server.go
22
server.go
@ -775,8 +775,26 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport.
|
|||||||
Delay: false,
|
Delay: false,
|
||||||
}
|
}
|
||||||
if err := s.sendResponse(t, stream, reply, s.opts.cp, opts); err != nil {
|
if err := s.sendResponse(t, stream, reply, s.opts.cp, opts); err != nil {
|
||||||
// TODO: Translate error into a status.Status error if necessary?
|
if err == io.EOF {
|
||||||
// TODO: Write status when appropriate.
|
// The entire stream is done (for unary RPC only).
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if s, ok := status.FromError(err); ok {
|
||||||
|
if e := t.WriteStatus(stream, s); e != nil {
|
||||||
|
grpclog.Printf("grpc: Server.processUnaryRPC failed to write status: %v", e)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch st := err.(type) {
|
||||||
|
case transport.ConnectionError:
|
||||||
|
// Nothing to do here.
|
||||||
|
case transport.StreamError:
|
||||||
|
if e := t.WriteStatus(stream, status.New(st.Code, st.Desc)); e != nil {
|
||||||
|
grpclog.Printf("grpc: Server.processUnaryRPC failed to write status %v", e)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("grpc: Unexpected error (%T) from sendResponse: %v", st, st))
|
||||||
|
}
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if trInfo != nil {
|
if trInfo != nil {
|
||||||
|
Reference in New Issue
Block a user