Skip to content

Commit

Permalink
userprovider: Return user not found error
Browse files Browse the repository at this point in the history
Return a proper NOT_FOUND error instead of INTERNAL when user is not found.
  • Loading branch information
rhafer committed Oct 14, 2021
1 parent 9238acf commit 580eef6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
20 changes: 12 additions & 8 deletions internal/grpc/services/userprovider/userprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,12 @@ func (s *service) Register(ss *grpc.Server) {
func (s *service) GetUser(ctx context.Context, req *userpb.GetUserRequest) (*userpb.GetUserResponse, error) {
user, err := s.usermgr.GetUser(ctx, req.UserId)
if err != nil {
// TODO(labkode): check for not found.
err = errors.Wrap(err, "userprovidersvc: error getting user")
res := &userpb.GetUserResponse{
Status: status.NewInternal(ctx, err, "error getting user"),
res := &userpb.GetUserResponse{}
if _, ok := err.(errtypes.NotFound); ok {
res.Status = status.NewNotFound(ctx, "user not found")
} else {
err = errors.Wrap(err, "userprovidersvc: error getting user")
res.Status = status.NewInternal(ctx, err, "error getting user")
}
return res, nil
}
Expand All @@ -145,10 +147,12 @@ func (s *service) GetUser(ctx context.Context, req *userpb.GetUserRequest) (*use
func (s *service) GetUserByClaim(ctx context.Context, req *userpb.GetUserByClaimRequest) (*userpb.GetUserByClaimResponse, error) {
user, err := s.usermgr.GetUserByClaim(ctx, req.Claim, req.Value)
if err != nil {
// TODO(labkode): check for not found.
err = errors.Wrap(err, "userprovidersvc: error getting user by claim")
res := &userpb.GetUserByClaimResponse{
Status: status.NewInternal(ctx, err, "error getting user by claim"),
res := &userpb.GetUserByClaimResponse{}
if _, ok := err.(errtypes.NotFound); ok {
res.Status = status.NewNotFound(ctx, fmt.Sprintf("user not found %s %s", req.Claim, req.Value))
} else {
err = errors.Wrap(err, "userprovidersvc: error getting user by claim")
res.Status = status.NewInternal(ctx, err, "error getting user by claim")
}
return res, nil
}
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/grpc/userprovider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ var _ = Describe("user providers", func() {
},
want: &userpb.GetUserResponse{
Status: &rpc.Status{
Code: 15,
Code: 6,
},
},
},
Expand All @@ -147,7 +147,7 @@ var _ = Describe("user providers", func() {
},
want: &userpb.GetUserResponse{
Status: &rpc.Status{
Code: 15,
Code: 6,
},
},
},
Expand All @@ -160,7 +160,7 @@ var _ = Describe("user providers", func() {
},
want: &userpb.GetUserResponse{
Status: &rpc.Status{
Code: 15,
Code: 6,
},
},
},
Expand Down

0 comments on commit 580eef6

Please sign in to comment.