Updated error fallbacks to generic error message

refs: https://github.com/TryGhost/Team/issues/1121

- We've decided on one  preferred message for unexpected errors
- We want to use this everywhere where we don't know what to display
- We now have a GENERIC_ERROR_MESSAGE constant that we should use
This commit is contained in:
Hannah Wolfe 2022-11-23 16:36:29 +00:00
parent 907319a507
commit e4dbf9b0fd
9 changed files with 17 additions and 9 deletions

View File

@ -1,4 +1,5 @@
import Component from '@ember/component';
import {GENERIC_ERROR_MESSAGE} from 'ghost-admin/services/notifications';
import {
UnsupportedMediaTypeError,
isRequestEntityTooLargeError,
@ -242,7 +243,8 @@ export default Component.extend({
} else if (error.payload && error.payload.errors && !isBlank(error.payload.errors[0].message)) {
message = htmlSafe(error.payload.errors[0].message);
} else {
message = 'Something went wrong :(';
console.error(error); // eslint-disable-line
message = GENERIC_ERROR_MESSAGE;
}
this.set('failureMessage', message);

View File

@ -1,5 +1,6 @@
import Component from '@ember/component';
import ghostPaths from 'ghost-admin/utils/ghost-paths';
import {GENERIC_ERROR_MESSAGE} from 'ghost-admin/services/notifications';
import {
UnsupportedMediaTypeError,
isRequestEntityTooLargeError,
@ -253,8 +254,8 @@ export default Component.extend({
} else if (!isBlank(error.payload?.errors?.[0]?.message)) {
message = error.payload.errors[0].message;
} else {
message = 'Something went wrong :(';
console.error(error); // eslint-disable-line
message = GENERIC_ERROR_MESSAGE;
}
this.set('failureMessage', message);

View File

@ -1,5 +1,6 @@
import ModalComponent from 'ghost-admin/components/modal-base';
import ghostPaths from 'ghost-admin/utils/ghost-paths';
import {GENERIC_ERROR_MESSAGE} from 'ghost-admin/services/notifications';
import {computed} from '@ember/object';
import {inject} from 'ghost-admin/decorators/inject';
import {
@ -95,7 +96,7 @@ export default ModalComponent.extend({
message = 'The file you uploaded was larger than the maximum file size your server allows.';
} else {
console.error(error); // eslint-disable-line
message = 'Something went wrong :(';
message = GENERIC_ERROR_MESSAGE;
}
this.set('errorMessage', message);

View File

@ -11,6 +11,7 @@ import classic from 'ember-classic-decorator';
import config from 'ghost-admin/config/environment';
import isNumber from 'ghost-admin/utils/isNumber';
import moment from 'moment-timezone';
import {GENERIC_ERROR_MESSAGE} from '../services/notifications';
import {action, computed} from '@ember/object';
import {alias, mapBy} from '@ember/object/computed';
import {capitalize} from '@ember/string';
@ -246,7 +247,7 @@ export default class EditorController extends Controller {
let transition = this.leaveEditorTransition;
if (!transition) {
this.notifications.showAlert('Sorry, there was an error in the application. Please let the Ghost team know what happened.', {type: 'error'});
this.notifications.showAlert(GENERIC_ERROR_MESSAGE, {type: 'error'});
return;
}

View File

@ -11,6 +11,7 @@ import classic from 'ember-classic-decorator';
import config from 'ghost-admin/config/environment';
import isNumber from 'ghost-admin/utils/isNumber';
import moment from 'moment-timezone';
import {GENERIC_ERROR_MESSAGE} from '../services/notifications';
import {action, computed} from '@ember/object';
import {alias, mapBy} from '@ember/object/computed';
import {capitalize} from '@ember/string';
@ -246,7 +247,7 @@ export default class LexicalEditorController extends Controller {
let transition = this.leaveEditorTransition;
if (!transition) {
this.notifications.showAlert('Sorry, there was an error in the application. Please let the Ghost team know what happened.', {type: 'error'});
this.notifications.showAlert(GENERIC_ERROR_MESSAGE, {type: 'error'});
return;
}

View File

@ -174,7 +174,7 @@ export default class NotificationsService extends Service {
}
options.key = ['api-error', options.key].compact().join('.');
let msg = options.defaultErrorText || 'There was a problem on the server, please try again.';
let msg = options.defaultErrorText || GENERIC_ERROR_MESSAGE;
if (resp?.name && GENERIC_ERROR_NAMES.includes(resp.name)) {
msg = GENERIC_ERROR_MESSAGE;

View File

@ -4,6 +4,7 @@ import Service from '@ember/service';
import ghostPaths from 'ghost-admin/utils/ghost-paths';
import hbs from 'htmlbars-inline-precompile';
import sinon from 'sinon';
import {GENERIC_ERROR_MESSAGE} from 'ghost-admin/services/notifications';
import {UnsupportedMediaTypeError} from 'ghost-admin/services/ajax';
import {click, find, findAll, render, settled, triggerEvent} from '@ember/test-helpers';
import {createFile, fileUpload} from '../../helpers/file-upload';
@ -213,7 +214,7 @@ describe('Integration: Component: gh-file-uploader', function () {
await fileUpload('input[type="file"]', ['test'], {name: 'test.csv'});
expect(findAll('.failed').length, 'error message is displayed').to.equal(1);
expect(find('.failed').textContent).to.match(/Something went wrong/);
expect(find('.failed').textContent).to.match(new RegExp(GENERIC_ERROR_MESSAGE));
});
it('triggers notifications.showAPIError for VersionMismatchError', async function () {

View File

@ -4,6 +4,7 @@ import Service from '@ember/service';
import ghostPaths from 'ghost-admin/utils/ghost-paths';
import hbs from 'htmlbars-inline-precompile';
import sinon from 'sinon';
import {GENERIC_ERROR_MESSAGE} from 'ghost-admin/services/notifications';
import {UnsupportedMediaTypeError} from 'ghost-admin/services/ajax';
import {click, find, findAll, render, settled, triggerEvent} from '@ember/test-helpers';
import {createFile, fileUpload} from '../../helpers/file-upload';
@ -205,7 +206,7 @@ describe('Integration: Component: gh-image-uploader', function () {
await fileUpload('input[type="file"]', ['test'], {name: 'test.png'});
expect(findAll('.failed').length, 'error message is displayed').to.equal(1);
expect(find('.failed').textContent).to.match(/Something went wrong/);
expect(find('.failed').textContent).to.match(new RegExp(GENERIC_ERROR_MESSAGE));
});
it('triggers notifications.showAPIError for VersionMismatchError', async function () {

View File

@ -193,7 +193,7 @@ describe('Unit: Service: notifications', function () {
notifications.showAPIError(resp);
});
expect(notifications.content).to.deep.equal([
{message: 'There was a problem on the server, please try again.', status: 'alert', type: 'error', key: 'api-error', actions: undefined, description: undefined, icon: undefined}
{message: GENERIC_ERROR_MESSAGE, status: 'alert', type: 'error', key: 'api-error', actions: undefined, description: undefined, icon: undefined}
]);
notifications.set('content', emberA());