Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion backend/e2e/sponsor-doc-utm-save.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ test("a failed autosave shows a loud NOT SAVED error, reports it, and Retry save
await page.locator("#sponsor-field-title").fill("Will fail first");
await expect(status(page)).toHaveAttribute("data-sponsor-save-state", "error", { timeout: 10_000 });
await expect(status(page)).toHaveAttribute("role", "alert");
await expect(status(page)).toContainText("NOT SAVED");
await expect(status(page)).toContainText("NOT SAVED: the server returned an error (500)");
await expect(status(page)).not.toContainText("Reload the page");
await expect.poll(() => reports.length).toBeGreaterThan(0);
await page.unroute("**/api/sponsor-docs/*", failPut);
await page.locator('[data-sponsor-action="retry-save"]').click();
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/surfaces/operations/sponsor-doc-autosave.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@ export const SPONSOR_DOC_AUTOSAVE_DELAY_MS = 1200;
// (it records a booking intent), so autosave keeps its saved value.
const EXPLICIT_SAVE_KEYS = ["slotChoice"];

/**
* Never tell the visitor to reload after a failed save: a reload throws the
* unsaved edits away. Timeouts, network errors and 5xx (already reported to
* the server by the request layer) get a save-specific explanation.
*/
export function notSavedMessage(err) {
const status = err?.status;
let cause;
if (status === "timeout") cause = "the server took too long to respond.";
else if (status === "network") cause = "the connection failed.";
else if (typeof status === "number" && status >= 500) cause = `the server returned an error (${status}).`;
if (cause) {
return `NOT SAVED: ${cause} Your edits are still in this form; do not reload. Click Retry save, or keep editing and it retries. The DataTalks.Club team has been notified.`;
}
return `NOT SAVED: ${err?.message || "Failed to save changes."} Your edits are still in this form.`;
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/test/sponsor-docs.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ test("typing autosaves after the debounce; a failed autosave is loud and Retry s
assert.equal(puts[0].content.headline, "Edited");
assert.equal(status().dataset.sponsorSaveState, "error");
assert.equal(status().getAttribute("role"), "alert");
assert.match(status().textContent, /NOT SAVED: Could not save: it took too long to respond/);
assert.match(status().textContent, /NOT SAVED: the server took too long to respond\. Your edits are still in this form; do not reload/);
failPuts = false;
await h.root.querySelector('[data-sponsor-action="retry-save"]').click();
await settle();
Expand Down