duh errors.Is instead of homegrown
This commit is contained in:
parent
ebd665ee25
commit
1472090da9
|
@ -235,7 +235,7 @@ func (s *Subscriber) connect(ctx context.Context) (*websocket.Conn, error) {
|
|||
conn, _, err := websocket.Dial(ctx, url, nil)
|
||||
if err != nil {
|
||||
log.WithError(err).Debugf("dial error")
|
||||
if checkForCancelled(err) {
|
||||
if errors.Is(err, context.Canceled) {
|
||||
return nil, err
|
||||
}
|
||||
log.Debugf("reconnecting in %s", b.Duration())
|
||||
|
@ -318,11 +318,3 @@ func (s *Subscriber) readloop(ctx context.Context, conn *websocket.Conn, msgs ch
|
|||
msgs <- msg
|
||||
}
|
||||
}
|
||||
|
||||
func checkForCancelled(err error) bool {
|
||||
next := err
|
||||
for next != nil && next != context.Canceled {
|
||||
next = errors.Unwrap(next)
|
||||
}
|
||||
return next == context.Canceled
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package client
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
|
@ -89,20 +88,3 @@ func TestCancelContextOnSubscribe(t *testing.T) {
|
|||
<-ctx.Done()
|
||||
|
||||
}
|
||||
|
||||
func TestIsContextCancelWrapped(t *testing.T) {
|
||||
|
||||
assert := assert.New(t)
|
||||
|
||||
assert.False(checkForCancelled(nil))
|
||||
assert.False(checkForCancelled(ErrConnectionFailed))
|
||||
assert.True(checkForCancelled(context.Canceled))
|
||||
|
||||
levelOne := fmt.Errorf("level one :%w", context.Canceled)
|
||||
assert.True(checkForCancelled(levelOne))
|
||||
levelTwo := fmt.Errorf("level two :%w", levelOne)
|
||||
assert.True(checkForCancelled(levelTwo))
|
||||
levelThree := fmt.Errorf("level two :%w", levelTwo)
|
||||
assert.True(checkForCancelled(levelThree))
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue