From a9bf6c66ed00b065d598d6afd16df4b4f59db46f Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Fri, 13 Sep 2024 11:30:03 +0100 Subject: [PATCH] Improved displayed error message when editor reaches bad saving state ref https://linear.app/tryghost/issue/ONC-323 - added explicit 404 handling to the editor's save task so we can display a more direct/useful error message --- ghost/admin/app/controllers/lexical-editor.js | 13 ++++++++++++- ghost/admin/tests/acceptance/editor-test.js | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ghost/admin/app/controllers/lexical-editor.js b/ghost/admin/app/controllers/lexical-editor.js index 467f1305aa..09b36cb4ae 100644 --- a/ghost/admin/app/controllers/lexical-editor.js +++ b/ghost/admin/app/controllers/lexical-editor.js @@ -22,7 +22,7 @@ import {inject} from 'ghost-admin/decorators/inject'; import {isBlank} from '@ember/utils'; import {isArray as isEmberArray} from '@ember/array'; import {isHostLimitError, isServerUnreachableError, isVersionMismatchError} from 'ghost-admin/services/ajax'; -import {isInvalidError} from 'ember-ajax/errors'; +import {isInvalidError, isNotFoundError} from 'ember-ajax/errors'; import {mobiledocToLexical} from '@tryghost/kg-converters'; import {inject as service} from '@ember/service'; import {slugify} from '@tryghost/string'; @@ -652,6 +652,17 @@ export default class LexicalEditorController extends Controller { return; } + // This shouldn't occur but we have a bug where a new post can get + // into a bad state where it's not saved but the store is treating + // it as saved and performing PUT requests with no id. We want to + // be noisy about this early to avoid data loss + if (isNotFoundError(error)) { + console.error(error); // eslint-disable-line no-console + Sentry.captureException(error, {tags: {savePostTask: true}}); + this._showErrorAlert(prevStatus, this.post.status, 'Editor has crashed. Please copy your content and start a new post.'); + return; + } + if (error && !isInvalidError(error)) { console.error(error); // eslint-disable-line no-console Sentry.captureException(error, {tags: {savePostTask: true}}); diff --git a/ghost/admin/tests/acceptance/editor-test.js b/ghost/admin/tests/acceptance/editor-test.js index 62bb5e05bf..32cbb81cb8 100644 --- a/ghost/admin/tests/acceptance/editor-test.js +++ b/ghost/admin/tests/acceptance/editor-test.js @@ -706,7 +706,8 @@ describe('Acceptance: Editor', function () { await pasteInEditor('Testing'); // we should see an error - previously this was failing silently - expect(find('.gh-alert-content')).to.have.trimmed.text('Resource could not be found.'); + // error message comes from editor's own handling rather than our generic API error fallback + expect(find('.gh-alert-content')).to.have.trimmed.text('Saving failed: Editor has crashed. Please copy your content and start a new post.'); }); }); });