Skip to content

Commit

Permalink
Change operator service error codes if Search attributes are not foun…
Browse files Browse the repository at this point in the history
…d or already exist
  • Loading branch information
Spikhalskiy committed Mar 21, 2022
1 parent b7100ae commit 81ece0d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions service/frontend/operator_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (h *OperatorHandlerImpl) AddSearchAttributes(ctx context.Context, request *
return nil, h.error(serviceerror.NewInvalidArgument(fmt.Sprintf(errSearchAttributeIsReservedMessage, saName)), scope, endpointName)
}
if currentSearchAttributes.IsDefined(saName) {
return nil, h.error(serviceerror.NewInvalidArgument(fmt.Sprintf(errSearchAttributeAlreadyExistsMessage, saName)), scope, endpointName)
return nil, h.error(serviceerror.NewAlreadyExist(fmt.Sprintf(errSearchAttributeAlreadyExistsMessage, saName)), scope, endpointName)
}
if _, ok := enumspb.IndexedValueType_name[int32(saType)]; !ok {
return nil, h.error(serviceerror.NewInvalidArgument(fmt.Sprintf(errUnknownSearchAttributeTypeMessage, saType)), scope, endpointName)
Expand Down Expand Up @@ -221,7 +221,7 @@ func (h *OperatorHandlerImpl) RemoveSearchAttributes(ctx context.Context, reques

for _, saName := range request.GetSearchAttributes() {
if !currentSearchAttributes.IsDefined(saName) {
return nil, h.error(serviceerror.NewInvalidArgument(fmt.Sprintf(errSearchAttributeDoesntExistMessage, saName)), scope, endpointName)
return nil, h.error(serviceerror.NewNotFound(fmt.Sprintf(errSearchAttributeDoesntExistMessage, saName)), scope, endpointName)
}
if _, ok := newCustomSearchAttributes[saName]; !ok {
return nil, h.error(serviceerror.NewInvalidArgument(fmt.Sprintf(errUnableToRemoveNonCustomSearchAttributesMessage, saName)), scope, endpointName)
Expand Down
8 changes: 4 additions & 4 deletions service/frontend/operator_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (s *operatorHandlerSuite) Test_AddSearchAttributes() {
"CustomTextField": enumspb.INDEXED_VALUE_TYPE_TEXT,
},
},
Expected: &serviceerror.InvalidArgument{Message: "Search attribute CustomTextField already exists."},
Expected: &serviceerror.AlreadyExists{Message: "Search attribute CustomTextField already exists."},
},
}
for _, testCase := range testCases3 {
Expand Down Expand Up @@ -174,7 +174,7 @@ func (s *operatorHandlerSuite) Test_AddSearchAttributes() {
"CustomTextField": enumspb.INDEXED_VALUE_TYPE_TEXT,
},
},
Expected: &serviceerror.InvalidArgument{Message: "Search attribute CustomTextField already exists."},
Expected: &serviceerror.AlreadyExists{Message: "Search attribute CustomTextField already exists."},
},
}
for _, testCase := range testCases2 {
Expand Down Expand Up @@ -315,7 +315,7 @@ func (s *operatorHandlerSuite) Test_RemoveSearchAttributes() {
"ProductId",
},
},
Expected: &serviceerror.InvalidArgument{Message: "Search attribute ProductId doesn't exist."},
Expected: &serviceerror.NotFound{Message: "Search attribute ProductId doesn't exist."},
},
}
for _, testCase := range testCases3 {
Expand Down Expand Up @@ -351,7 +351,7 @@ func (s *operatorHandlerSuite) Test_RemoveSearchAttributes() {
"ProductId",
},
},
Expected: &serviceerror.InvalidArgument{Message: "Search attribute ProductId doesn't exist."},
Expected: &serviceerror.NotFound{Message: "Search attribute ProductId doesn't exist."},
},
}
for _, testCase := range testCases2 {
Expand Down

0 comments on commit 81ece0d

Please sign in to comment.