Skip to content

Commit f7ed394

Browse files
authored
Change operator service error codes if Search attributes are not found or already exist (#2627)
1 parent f4c0852 commit f7ed394

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

service/frontend/operator_handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (h *OperatorHandlerImpl) AddSearchAttributes(ctx context.Context, request *
150150
return nil, h.error(serviceerror.NewInvalidArgument(fmt.Sprintf(errSearchAttributeIsReservedMessage, saName)), scope, endpointName)
151151
}
152152
if currentSearchAttributes.IsDefined(saName) {
153-
return nil, h.error(serviceerror.NewInvalidArgument(fmt.Sprintf(errSearchAttributeAlreadyExistsMessage, saName)), scope, endpointName)
153+
return nil, h.error(serviceerror.NewAlreadyExist(fmt.Sprintf(errSearchAttributeAlreadyExistsMessage, saName)), scope, endpointName)
154154
}
155155
if _, ok := enumspb.IndexedValueType_name[int32(saType)]; !ok {
156156
return nil, h.error(serviceerror.NewInvalidArgument(fmt.Sprintf(errUnknownSearchAttributeTypeMessage, saType)), scope, endpointName)
@@ -221,7 +221,7 @@ func (h *OperatorHandlerImpl) RemoveSearchAttributes(ctx context.Context, reques
221221

222222
for _, saName := range request.GetSearchAttributes() {
223223
if !currentSearchAttributes.IsDefined(saName) {
224-
return nil, h.error(serviceerror.NewInvalidArgument(fmt.Sprintf(errSearchAttributeDoesntExistMessage, saName)), scope, endpointName)
224+
return nil, h.error(serviceerror.NewNotFound(fmt.Sprintf(errSearchAttributeDoesntExistMessage, saName)), scope, endpointName)
225225
}
226226
if _, ok := newCustomSearchAttributes[saName]; !ok {
227227
return nil, h.error(serviceerror.NewInvalidArgument(fmt.Sprintf(errUnableToRemoveNonCustomSearchAttributesMessage, saName)), scope, endpointName)

service/frontend/operator_handler_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (s *operatorHandlerSuite) Test_AddSearchAttributes() {
138138
"CustomTextField": enumspb.INDEXED_VALUE_TYPE_TEXT,
139139
},
140140
},
141-
Expected: &serviceerror.InvalidArgument{Message: "Search attribute CustomTextField already exists."},
141+
Expected: &serviceerror.AlreadyExists{Message: "Search attribute CustomTextField already exists."},
142142
},
143143
}
144144
for _, testCase := range testCases3 {
@@ -174,7 +174,7 @@ func (s *operatorHandlerSuite) Test_AddSearchAttributes() {
174174
"CustomTextField": enumspb.INDEXED_VALUE_TYPE_TEXT,
175175
},
176176
},
177-
Expected: &serviceerror.InvalidArgument{Message: "Search attribute CustomTextField already exists."},
177+
Expected: &serviceerror.AlreadyExists{Message: "Search attribute CustomTextField already exists."},
178178
},
179179
}
180180
for _, testCase := range testCases2 {
@@ -315,7 +315,7 @@ func (s *operatorHandlerSuite) Test_RemoveSearchAttributes() {
315315
"ProductId",
316316
},
317317
},
318-
Expected: &serviceerror.InvalidArgument{Message: "Search attribute ProductId doesn't exist."},
318+
Expected: &serviceerror.NotFound{Message: "Search attribute ProductId doesn't exist."},
319319
},
320320
}
321321
for _, testCase := range testCases3 {
@@ -351,7 +351,7 @@ func (s *operatorHandlerSuite) Test_RemoveSearchAttributes() {
351351
"ProductId",
352352
},
353353
},
354-
Expected: &serviceerror.InvalidArgument{Message: "Search attribute ProductId doesn't exist."},
354+
Expected: &serviceerror.NotFound{Message: "Search attribute ProductId doesn't exist."},
355355
},
356356
}
357357
for _, testCase := range testCases2 {

0 commit comments

Comments
 (0)