[#287] client: Fix error handling after dialing
Before, when error was presented and neither `Canceled` nor `DeadlineExceeded`, that method returned no error on failed dial. Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
This commit is contained in:
parent
a8824fed89
commit
e44fe4bde0
1 changed files with 10 additions and 17 deletions
|
@ -106,28 +106,21 @@ func (c *Client) Dial(ctx context.Context, prm PrmDial) error {
|
|||
_, err := rpc.Balance(&c.c, new(v2accounting.BalanceRequest),
|
||||
client.WithContext(ctx),
|
||||
)
|
||||
if err != nil {
|
||||
var ctxErr error
|
||||
|
||||
// return context errors since they signal about dial problem
|
||||
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
||||
ctxErr = err
|
||||
} else if st, ok := status.FromError(err); ok && st.Code() == codes.Canceled {
|
||||
ctxErr = context.Canceled
|
||||
} else if ok && st.Code() == codes.DeadlineExceeded {
|
||||
ctxErr = context.DeadlineExceeded
|
||||
}
|
||||
if ctxErr != nil {
|
||||
if conn := c.c.Conn(); conn != nil {
|
||||
_ = conn.Close()
|
||||
}
|
||||
return ctxErr
|
||||
}
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch st, ok := status.FromError(err); {
|
||||
case errors.Is(err, context.Canceled) || (ok && st.Code() == codes.Canceled):
|
||||
return context.Canceled
|
||||
case errors.Is(err, context.DeadlineExceeded) || (ok && st.Code() == codes.DeadlineExceeded):
|
||||
return context.DeadlineExceeded
|
||||
default:
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// sets underlying provider of frostFSAPIServer. The method is used for testing as an approach
|
||||
// to skip Dial stage and override FrostFS API server. MUST NOT be used outside test code.
|
||||
// In real applications wrapper over git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client
|
||||
|
|
Loading…
Reference in a new issue