diff --git a/src/actions/RecordActions.js b/src/actions/RecordActions.js index 5024cbb9..15c64d8f 100644 --- a/src/actions/RecordActions.js +++ b/src/actions/RecordActions.js @@ -106,11 +106,9 @@ export function createRecord(record) { }) .catch((error) => { dispatch(saveRecordError(error.response.data, record, ACTION_FLAG.CREATE_ENTITY)); - dispatch( - publishMessage( - errorMessage("record.save-error", { error: getState().intl.messages[error.response.data.messageId] }), - ), - ); + const errorMessageText = + getState().intl.messages[error.response.data.messageId] || error.response.data || "An error occurred"; + dispatch(publishMessage(errorMessage("record.save-error", { error: errorMessageText }))); }); }; } diff --git a/tests/__tests__/actions/RecordActions.spec.jsx b/tests/__tests__/actions/RecordActions.spec.jsx index 8c021031..8cede4d8 100644 --- a/tests/__tests__/actions/RecordActions.spec.jsx +++ b/tests/__tests__/actions/RecordActions.spec.jsx @@ -165,7 +165,7 @@ describe("Record asynchronous actions", function () { { type: ActionConstants.PUBLISH_MESSAGE, message: successMessage("record.save-success") }, { type: ActionConstants.LOAD_RECORDS_SUCCESS, records }, ]; - + mockApi.onGet(`${API_URL}/rest/users/current`).reply(200, { institution: "Test Institution" }); mockApi.onPost(`${API_URL}/rest/records`).reply(200, null, { location }); mockApi.onGet(`${API_URL}/rest/records`).reply(200, records, {});