From 9a1a7ade85b0436d6b664379779f1220d87ef6e7 Mon Sep 17 00:00:00 2001 From: Alexander Melentyev <55826637+alexander-melentyev@users.noreply.github.com> Date: Tue, 28 Sep 2021 18:01:29 +0300 Subject: [PATCH] Use errors.Is for error handling (#1187) --- sd/consul/instancer.go | 2 +- transport/http/jsonrpc/server_test.go | 2 +- transport/http/server_test.go | 2 +- transport/nats/subscriber_test.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sd/consul/instancer.go b/sd/consul/instancer.go index ce267ec1e..11106654b 100644 --- a/sd/consul/instancer.go +++ b/sd/consul/instancer.go @@ -70,7 +70,7 @@ func (s *Instancer) loop(lastIndex uint64) { index := lastIndex instances, index, err = s.getInstances(lastIndex, s.quitc) switch { - case err == errStopped: + case errors.Is(err, errStopped): return // stopped via quitc case err != nil: s.logger.Log("err", err) diff --git a/transport/http/jsonrpc/server_test.go b/transport/http/jsonrpc/server_test.go index c05435ddc..210d5b34c 100644 --- a/transport/http/jsonrpc/server_test.go +++ b/transport/http/jsonrpc/server_test.go @@ -152,7 +152,7 @@ func TestServerBadEncode(t *testing.T) { func TestServerErrorEncoder(t *testing.T) { errTeapot := errors.New("teapot") code := func(err error) int { - if err == errTeapot { + if errors.Is(err, errTeapot) { return http.StatusTeapot } return http.StatusInternalServerError diff --git a/transport/http/server_test.go b/transport/http/server_test.go index c4359272e..5c0fadb29 100644 --- a/transport/http/server_test.go +++ b/transport/http/server_test.go @@ -59,7 +59,7 @@ func TestServerBadEncode(t *testing.T) { func TestServerErrorEncoder(t *testing.T) { errTeapot := errors.New("teapot") code := func(err error) int { - if err == errTeapot { + if errors.Is(err, errTeapot) { return http.StatusTeapot } return http.StatusInternalServerError diff --git a/transport/nats/subscriber_test.go b/transport/nats/subscriber_test.go index fc97c1fb7..d45fe4650 100644 --- a/transport/nats/subscriber_test.go +++ b/transport/nats/subscriber_test.go @@ -116,7 +116,7 @@ func TestSubscriberErrorEncoder(t *testing.T) { errTeapot := errors.New("teapot") code := func(err error) error { - if err == errTeapot { + if errors.Is(err, errTeapot) { return err } return errors.New("dang")