Skip to content

Commit

Permalink
Improved displayed error message when editor reaches bad saving state
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kevinansfield committed Sep 13, 2024
1 parent f054205 commit a9bf6c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 12 additions & 1 deletion ghost/admin/app/controllers/lexical-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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}});
Expand Down
3 changes: 2 additions & 1 deletion ghost/admin/tests/acceptance/editor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
});
});
});

0 comments on commit a9bf6c6

Please sign in to comment.