From 247707f5835bfed9da404c88dcb10d021c2c6a44 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Mon, 16 Mar 2020 10:30:56 +0000 Subject: [PATCH] Return store.ErrNotFound if not found when calling over rpc (#1353) Co-authored-by: Ben Toogood --- api/server/auth/auth.go | 1 + store/service/service.go | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index c57c7b50..a7391c18 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -63,6 +63,7 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { // If there is no auth login url set, 401 if loginURL == "" { w.WriteHeader(401) + return } // Redirect to the login path diff --git a/store/service/service.go b/store/service/service.go index 5b448a8c..90443744 100644 --- a/store/service/service.go +++ b/store/service/service.go @@ -7,6 +7,7 @@ import ( "time" "github.com/micro/go-micro/v2/client" + "github.com/micro/go-micro/v2/errors" "github.com/micro/go-micro/v2/metadata" "github.com/micro/go-micro/v2/store" pb "github.com/micro/go-micro/v2/store/service/proto" @@ -61,7 +62,9 @@ func (s *serviceStore) Context() context.Context { // Sync all the known records func (s *serviceStore) List(opts ...store.ListOption) ([]string, error) { stream, err := s.Client.List(s.Context(), &pb.ListRequest{}, client.WithAddress(s.Nodes...)) - if err != nil { + if verr, ok := err.(*errors.Error); ok && verr.Code == 404 { + return nil, store.ErrNotFound + } else if err != nil { return nil, err } defer stream.Close() @@ -98,7 +101,9 @@ func (s *serviceStore) Read(key string, opts ...store.ReadOption) ([]*store.Reco Prefix: options.Prefix, }, }, client.WithAddress(s.Nodes...)) - if err != nil { + if verr, ok := err.(*errors.Error); ok && verr.Code == 404 { + return nil, store.ErrNotFound + } else if err != nil { return nil, err } @@ -133,6 +138,9 @@ func (s *serviceStore) Delete(key string, opts ...store.DeleteOption) error { _, err := s.Client.Delete(s.Context(), &pb.DeleteRequest{ Key: key, }, client.WithAddress(s.Nodes...)) + if verr, ok := err.(*errors.Error); ok && verr.Code == 404 { + return store.ErrNotFound + } return err }