Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Fix: UXW-569 Add Error message for failed document saves (#62834)

Brad Andersoncbe38462e270
diff --git a/e2e/test/scenarios/documents/documents.cy.spec.ts b/e2e/test/scenarios/documents/documents.cy.spec.ts
index 893eb72dfff..1b87a1f3008 100644
--- a/e2e/test/scenarios/documents/documents.cy.spec.ts
+++ b/e2e/test/scenarios/documents/documents.cy.spec.ts
@@ -717,6 +717,51 @@ H.describeWithSnowplowEE("documents", () => {
});
});
});
+
+ describe("error handling", () => {
+ it("should display an error toast when creating a new document fails", () => {
+ // setup
+ cy.intercept("POST", "/api/ee/document", { statusCode: 500 });
+ cy.visit("/document/new");
+
+ // make changes and attempt to save
+ cy.findByRole("textbox", { name: "Document Title" }).type("Title");
+ H.documentSaveButton().click();
+ H.entityPickerModalTab("Collections").click();
+ H.entityPickerModalItem(0, "Our analytics")
+ .should("have.attr", "data-active", "true")
+ .click();
+ H.entityPickerModal().findByRole("button", { name: "Select" }).click();
+
+ // assert error toast is visible and user can reattempt save
+ cy.findByTestId("toast-undo")
+ .should("be.visible")
+ .and("contain.text", "Error saving document");
+ H.documentSaveButton().should("be.visible");
+ });
+
+ it("should display an error toast when updating a document fails", () => {
+ // setup
+ cy.intercept("PUT", "/api/ee/document/*", { statusCode: 500 });
+ H.createDocument({
+ name: "Test Document",
+ document: { type: "doc", content: [] },
+ idAlias: "documentId",
+ });
+ cy.get("@documentId").then((id) => cy.visit(`/document/${id}`));
+
+ // make changes and attempt to save
+ H.documentContent().click();
+ H.addToDocument("aaa");
+ H.documentSaveButton().click();
+
+ // assert error toast is visible and user can reattempt save
+ cy.findByTestId("toast-undo")
+ .should("be.visible")
+ .and("contain.text", "Error saving document");
+ H.documentSaveButton().should("be.visible");
+ });
+ });
});
const assertOnlyOneOptionActive = (
diff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.tsx b/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.tsx
index ac0ac36f5b2..6868dd26085 100644
--- a/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/documents/components/DocumentPage.tsx
@@ -291,7 +291,7 @@ export const DocumentPage = ({
dispatch(push(`/document/${_document.id}`));
});
}
- return response.data;
+ return response;
},
)
: createDocument({
@@ -305,16 +305,18 @@ export const DocumentPage = ({
dispatch(replace(`/document/${_document.id}`));
});
}
- return response.data;
+ return response;
}));
- if (result) {
+ if (result.data) {
sendToast({
message: documentData?.id ? t`Document saved` : t`Document created`,
});
dispatch(clearDraftCards());
// Mark document as clean
setHasUnsavedEditorChanges(false);
+ } else if (result.error) {
+ throw result.error;
}
} catch (error) {
console.error("Failed to save document:", error);