Skip to content

Commit

Permalink
Fix an issue from previous PR
Browse files Browse the repository at this point in the history
In elastic#104024, the error handling incorrectly used the `message` property on the response, when it should have been the attributes.errors array.
  • Loading branch information
scottybollinger committed Jul 5, 2021
1 parent f5e7b46 commit 3295dc4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ export const SchemaLogic = kea<MakeLogicType<SchemaValues, SchemaActions>>({
} 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);
Expand Down

0 comments on commit 3295dc4

Please sign in to comment.