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 {
return err
}
if err == ErrClientConnClosing {
return Errorf(codes.FailedPrecondition, "%v", err)
}
if err == errConnClosing {
if c.failFast {
return Errorf(codes.Unavailable, "%v", errConnClosing)

View File

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

View File

@ -401,7 +401,13 @@ func toRPCErr(err error) error {
code: codes.Canceled,
desc: err.Error(),
}
case ErrClientConnClosing:
return rpcError{
code: codes.FailedPrecondition,
desc: err.Error(),
}
}
}
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 {
return nil, err
}
if err == ErrClientConnClosing {
return nil, Errorf(codes.FailedPrecondition, "%v", err)
}
if err == errConnClosing {
if c.failFast {
return nil, Errorf(codes.Unavailable, "%v", errConnClosing)