refactor error handling a bit

This commit is contained in:
iamqizhao
2016-06-29 15:21:44 -07:00
parent 213a20c4fe
commit be59d023f2
4 changed files with 7 additions and 7 deletions

View File

@ -158,9 +158,6 @@ func Invoke(ctx context.Context, method string, args, reply interface{}, cc *Cli
if _, ok := err.(rpcError); ok { if _, ok := err.(rpcError); ok {
return err return err
} }
if err == ErrClientConnClosing {
return Errorf(codes.FailedPrecondition, "%v", err)
}
if err == errConnClosing { if err == errConnClosing {
if c.failFast { if c.failFast {
return Errorf(codes.Unavailable, "%v", errConnClosing) return Errorf(codes.Unavailable, "%v", errConnClosing)

View File

@ -431,7 +431,7 @@ func (cc *ClientConn) getTransport(ctx context.Context, opts BalancerGetOptions)
cc.mu.RLock() cc.mu.RLock()
if cc.conns == nil { if cc.conns == nil {
cc.mu.RUnlock() cc.mu.RUnlock()
return nil, nil, ErrClientConnClosing return nil, nil, toRPCErr(ErrClientConnClosing)
} }
ac, ok := cc.conns[addr] ac, ok := cc.conns[addr]
cc.mu.RUnlock() cc.mu.RUnlock()

View File

@ -401,8 +401,14 @@ func toRPCErr(err error) error {
code: codes.Canceled, code: codes.Canceled,
desc: err.Error(), desc: err.Error(),
} }
case ErrClientConnClosing:
return rpcError{
code: codes.FailedPrecondition,
desc: err.Error(),
} }
} }
}
return Errorf(codes.Unknown, "%v", err) return Errorf(codes.Unknown, "%v", err)
} }

View File

@ -152,9 +152,6 @@ func NewClientStream(ctx context.Context, desc *StreamDesc, cc *ClientConn, meth
if _, ok := err.(rpcError); ok { if _, ok := err.(rpcError); ok {
return nil, err return nil, err
} }
if err == ErrClientConnClosing {
return nil, Errorf(codes.FailedPrecondition, "%v", err)
}
if err == errConnClosing { if err == errConnClosing {
if c.failFast { if c.failFast {
return nil, Errorf(codes.Unavailable, "%v", errConnClosing) return nil, Errorf(codes.Unavailable, "%v", errConnClosing)