Skip to content

teams-service: cut down "create team" error strings #1134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions components/teams-service/server/v1/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package v1

import (
"context"
"fmt"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -60,10 +59,7 @@ func (s *Server) CreateTeam(ctx context.Context, req *teams.CreateTeamReq) (*tea
var err error
if team, err = s.service.Storage.StoreTeam(ctx, req.Name, req.Description); err != nil {
if err == storage.ErrConflict {
return nil, status.Errorf(
codes.AlreadyExists,
"unable to create team: a team with name %q already exists.",
req.Name)
return nil, status.Errorf(codes.AlreadyExists, "team with name %q already exists", req.Name)
}
return nil, status.Error(codes.Internal, err.Error())
}
Expand Down Expand Up @@ -129,9 +125,7 @@ func (s *Server) DeleteTeam(ctx context.Context, req *teams.DeleteTeamReq) (*tea
})
if err != nil {
s.service.Logger.Warnf("failed to purge subjects on team delete: %s", err.Error())
return nil, status.Error(codes.Internal,
fmt.Sprintf("the team named %s with id %s was successfully deleted but its "+
"subject could not be purged from the policies: %s", team.Name, team.ID, err.Error()))
return nil, status.Errorf(codes.Internal, "failed to purge team %q from policies: %s", team.ID, err.Error())
}

return &teams.DeleteTeamResp{
Expand Down
12 changes: 3 additions & 9 deletions components/teams-service/server/v2/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package v2

import (
"context"
"fmt"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -64,10 +63,7 @@ func (s *Server) CreateTeam(ctx context.Context,
var err error
if team, err = s.service.Storage.StoreTeamWithProjects(ctx, req.Id, req.Name, req.Projects); err != nil {
if err == storage.ErrConflict {
return nil, status.Errorf(
codes.AlreadyExists,
"unable to create team: a team with id %q already exists.",
req.Id)
return nil, status.Errorf(codes.AlreadyExists, "team with ID %q already exists", req.Id)
}
return nil, status.Error(codes.Internal, err.Error())
}
Expand Down Expand Up @@ -95,9 +91,7 @@ func (s *Server) DeleteTeam(ctx context.Context, req *teams.DeleteTeamReq) (*tea
})
if err != nil {
s.service.Logger.Warnf("failed to purge subjects on team delete: %s", err.Error())
return nil, status.Error(codes.Internal,
fmt.Sprintf("the team named %q with id %q was successfully deleted but its "+
"subject could not be purged from the policies: %s", team.Name, req.Id, err.Error()))
return nil, status.Errorf(codes.Internal, "failed to purge team %q from policies: %s", req.Id, err.Error())
}

return &teams.DeleteTeamResp{
Expand Down Expand Up @@ -127,7 +121,7 @@ func (s *Server) AddTeamMembers(ctx context.Context,
req *teams.AddTeamMembersReq) (*teams.AddTeamMembersResp, error) {

if len(req.UserIds) == 0 {
return nil, status.Error(codes.InvalidArgument, "missing user ids")
return nil, status.Error(codes.InvalidArgument, "missing user IDs")
}
// TODO (tc): The storage interface is still using V1 verbiage, so
// name is really the ID in V2 terms. We'll refactor at GA when V1 is removed.
Expand Down