diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/schema/schema_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/schema/schema_logic.test.ts index 3e8322145dad6..d642900aea169 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/schema/schema_logic.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/schema/schema_logic.test.ts @@ -325,10 +325,11 @@ describe('SchemaLogic', () => { }); it('handles duplicate', () => { + const onSchemaSetFormErrorsSpy = jest.spyOn(SchemaLogic.actions, 'onSchemaSetFormErrors'); SchemaLogic.actions.onInitializeSchema(serverResponse); SchemaLogic.actions.addNewField('foo', SchemaType.Number); - expect(setErrorMessage).toHaveBeenCalledWith('New field already exists: foo.'); + expect(onSchemaSetFormErrorsSpy).toHaveBeenCalledWith(['New field already exists: foo.']); }); }); @@ -393,8 +394,10 @@ describe('SchemaLogic', () => { it('handles error with message', async () => { const onSchemaSetFormErrorsSpy = jest.spyOn(SchemaLogic.actions, 'onSchemaSetFormErrors'); - // We expect body.message to be a string[] when it is present - http.post.mockReturnValue(Promise.reject({ body: { message: ['this is an error'] } })); + // We expect body.attributes.errors to be a string[] when it is present + http.post.mockReturnValue( + Promise.reject({ body: { attributes: { errors: ['this is an error'] } } }) + ); SchemaLogic.actions.setServerField(schema, ADD); await nextTick(); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/schema/schema_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/schema/schema_logic.ts index 7af074d412a60..f43be974102b2 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/schema/schema_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/schema/schema_logic.ts @@ -301,15 +301,15 @@ export const SchemaLogic = kea>({ addNewField: ({ fieldName, newFieldType }) => { if (fieldName in values.activeSchema) { window.scrollTo(0, 0); - setErrorMessage( + actions.onSchemaSetFormErrors([ i18n.translate( 'xpack.enterpriseSearch.workplaceSearch.contentSource.schema.newFieldExists.message', { defaultMessage: 'New field already exists: {fieldName}.', values: { fieldName }, } - ) - ); + ), + ]); } else { const schema = cloneDeep(values.activeSchema); schema[fieldName] = newFieldType; @@ -350,8 +350,8 @@ export const SchemaLogic = kea>({ } catch (e) { window.scrollTo(0, 0); if (isAdding) { - // We expect body.message to be a string[] for actions.onSchemaSetFormErrors - const message: string[] = e?.body?.message || [defaultErrorMessage]; + // We expect body.attributes.errors to be a string[] for actions.onSchemaSetFormErrors + const message: string[] = e?.body?.attributes?.errors || [defaultErrorMessage]; actions.onSchemaSetFormErrors(message); } else { flashAPIErrors(e);