0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

Fixed duplicate error messages from API

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

- In certain cases our API sends the same data for message and context.
- We will also fix this server-side, but we should also be smart in the UI and not show duplicate info
This commit is contained in:
Hannah Wolfe 2022-11-23 14:57:32 +00:00
parent 4ed245a405
commit c740eecaec
2 changed files with 19 additions and 1 deletions

View file

@ -186,7 +186,7 @@ export default class NotificationsService extends Service {
msg = resp.message;
}
if (!isBlank(resp?.context)) {
if (!isBlank(resp?.context) && resp?.context !== msg) {
msg = `${msg} ${resp.context}`;
}

View file

@ -274,6 +274,24 @@ describe('Unit: Service: notifications', function () {
expect(alert.key).to.equal('api-error');
});
it('#showAPIError does not add context to message if it duplicates the message', function () {
let notifications = this.owner.lookup('service:notifications');
let error = new AjaxError({errors: [{
message: 'Authorization Error.',
context: 'Authorization Error.'
}]});
run(() => {
notifications.showAPIError(error);
});
let [alert] = notifications.alerts;
expect(alert.message).to.equal('Authorization Error.');
expect(alert.status).to.equal('alert');
expect(alert.type).to.equal('error');
expect(alert.key).to.equal('api-error');
});
it('#showAPIError shows generic error for built-in error types', function () {
let notifications = this.owner.lookup('service:notifications');
const error = new TypeError('Testing');