Return store.ErrNotFound if not found when calling over rpc (#1353)

Co-authored-by: Ben Toogood <ben@micro.mu>
This commit is contained in:
ben-toogood 2020-03-16 10:30:56 +00:00 committed by GitHub
parent d91c14eb30
commit 247707f583
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -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

View File

@ -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
}