refactor error handling a bit
This commit is contained in:
3
call.go
3
call.go
@ -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)
|
||||||
|
@ -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()
|
||||||
|
@ -401,7 +401,13 @@ 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)
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
|
Reference in New Issue
Block a user