mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 14:17:22 +01:00
do not show "Notification not found" error messages (#10931)
* start fixing #10391 * do not show snackbars for notifications not found * revert message changes * update tests * add new test * fix property
This commit is contained in:
@@ -5,7 +5,9 @@ import {
|
|||||||
BadRequest,
|
BadRequest,
|
||||||
InternalServerError,
|
InternalServerError,
|
||||||
NotFound,
|
NotFound,
|
||||||
|
NotificationNotFound,
|
||||||
} from '../../../../website/server/libs/errors';
|
} from '../../../../website/server/libs/errors';
|
||||||
|
import i18n from '../../../../website/common/script/i18n';
|
||||||
|
|
||||||
describe('Custom Errors', () => {
|
describe('Custom Errors', () => {
|
||||||
describe('CustomError', () => {
|
describe('CustomError', () => {
|
||||||
@@ -66,6 +68,23 @@ describe('Custom Errors', () => {
|
|||||||
|
|
||||||
expect(notAuthorizedError.message).to.eql('Custom Error Message');
|
expect(notAuthorizedError.message).to.eql('Custom Error Message');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('NotificationNotFound', () => {
|
||||||
|
it('is an instance of NotFound', () => {
|
||||||
|
const notificationNotFoundErr = new NotificationNotFound();
|
||||||
|
expect(notificationNotFoundErr).to.be.an.instanceOf(NotFound);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('it returns an http code of 404', () => {
|
||||||
|
const notificationNotFoundErr = new NotificationNotFound();
|
||||||
|
expect(notificationNotFoundErr.httpCode).to.eql(404);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns a standard message', () => {
|
||||||
|
const notificationNotFoundErr = new NotificationNotFound();
|
||||||
|
expect(notificationNotFoundErr.message).to.eql(i18n.t('messageNotificationNotFound'));
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('BadRequest', () => {
|
describe('BadRequest', () => {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ describe('POST /notifications/:notificationId/read', () => {
|
|||||||
|
|
||||||
await expect(user.post(`/notifications/${dummyId}/read`)).to.eventually.be.rejected.and.eql({
|
await expect(user.post(`/notifications/${dummyId}/read`)).to.eventually.be.rejected.and.eql({
|
||||||
code: 404,
|
code: 404,
|
||||||
error: 'NotFound',
|
error: 'NotificationNotFound',
|
||||||
message: t('messageNotificationNotFound'),
|
message: t('messageNotificationNotFound'),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ describe('POST /notifications/:notificationId/see', () => {
|
|||||||
|
|
||||||
await expect(user.post(`/notifications/${dummyId}/see`)).to.eventually.be.rejected.and.eql({
|
await expect(user.post(`/notifications/${dummyId}/see`)).to.eventually.be.rejected.and.eql({
|
||||||
code: 404,
|
code: 404,
|
||||||
error: 'NotFound',
|
error: 'NotificationNotFound',
|
||||||
message: t('messageNotificationNotFound'),
|
message: t('messageNotificationNotFound'),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ describe('POST /notifications/read', () => {
|
|||||||
notificationIds: [dummyId],
|
notificationIds: [dummyId],
|
||||||
})).to.eventually.be.rejected.and.eql({
|
})).to.eventually.be.rejected.and.eql({
|
||||||
code: 404,
|
code: 404,
|
||||||
error: 'NotFound',
|
error: 'NotificationNotFound',
|
||||||
message: t('messageNotificationNotFound'),
|
message: t('messageNotificationNotFound'),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ describe('POST /notifications/see', () => {
|
|||||||
notificationIds: [dummyId],
|
notificationIds: [dummyId],
|
||||||
})).to.eventually.be.rejected.and.eql({
|
})).to.eventually.be.rejected.and.eql({
|
||||||
code: 404,
|
code: 404,
|
||||||
error: 'NotFound',
|
error: 'NotificationNotFound',
|
||||||
message: t('messageNotificationNotFound'),
|
message: t('messageNotificationNotFound'),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -362,6 +362,7 @@ export default {
|
|||||||
const errorMessage = errorData.message || errorData;
|
const errorMessage = errorData.message || errorData;
|
||||||
|
|
||||||
// Check for conditions to reset the user auth
|
// Check for conditions to reset the user auth
|
||||||
|
// TODO use a specific error like NotificationNotFound instead of checking for the string
|
||||||
const invalidUserMessage = [this.$t('invalidCredentials'), 'Missing authentication headers.'];
|
const invalidUserMessage = [this.$t('invalidCredentials'), 'Missing authentication headers.'];
|
||||||
if (invalidUserMessage.indexOf(errorMessage) !== -1) {
|
if (invalidUserMessage.indexOf(errorMessage) !== -1) {
|
||||||
this.$store.dispatch('auth:logout');
|
this.$store.dispatch('auth:logout');
|
||||||
@@ -371,12 +372,6 @@ export default {
|
|||||||
let snackbarTimeout = false;
|
let snackbarTimeout = false;
|
||||||
if (error.response.status === 502) snackbarTimeout = true;
|
if (error.response.status === 502) snackbarTimeout = true;
|
||||||
|
|
||||||
const notificationNotFoundMessage = [
|
|
||||||
this.$t('messageNotificationNotFound'),
|
|
||||||
this.$t('messageNotificationNotFound', 'en'),
|
|
||||||
];
|
|
||||||
if (notificationNotFoundMessage.indexOf(errorMessage) !== -1) snackbarTimeout = true;
|
|
||||||
|
|
||||||
let errorsToShow = [];
|
let errorsToShow = [];
|
||||||
// show only the first error for each param
|
// show only the first error for each param
|
||||||
let paramErrorsFound = {};
|
let paramErrorsFound = {};
|
||||||
@@ -390,6 +385,9 @@ export default {
|
|||||||
} else {
|
} else {
|
||||||
errorsToShow.push(errorMessage);
|
errorsToShow.push(errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ignore NotificationNotFound errors, see https://github.com/HabitRPG/habitica/issues/10391
|
||||||
|
if (errorData.error !== 'NotificationNotFound') {
|
||||||
// dispatch as one snackbar notification
|
// dispatch as one snackbar notification
|
||||||
this.$store.dispatch('snackbars:add', {
|
this.$store.dispatch('snackbars:add', {
|
||||||
title: 'Habitica',
|
title: 'Habitica',
|
||||||
@@ -398,6 +396,7 @@ export default {
|
|||||||
timeout: snackbarTimeout,
|
timeout: snackbarTimeout,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { authWithHeaders } from '../../middlewares/auth';
|
import { authWithHeaders } from '../../middlewares/auth';
|
||||||
import {
|
import {
|
||||||
NotFound,
|
NotificationNotFound,
|
||||||
} from '../../libs/errors';
|
} from '../../libs/errors';
|
||||||
import {
|
import {
|
||||||
model as User,
|
model as User,
|
||||||
@@ -37,7 +37,7 @@ api.readNotification = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
throw new NotFound(res.t('messageNotificationNotFound'));
|
throw new NotificationNotFound(req.language);
|
||||||
}
|
}
|
||||||
|
|
||||||
user.notifications.splice(index, 1);
|
user.notifications.splice(index, 1);
|
||||||
@@ -81,7 +81,7 @@ api.readNotifications = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
throw new NotFound(res.t('messageNotificationNotFound'));
|
throw new NotificationNotFound(req.language);
|
||||||
}
|
}
|
||||||
|
|
||||||
user.notifications.splice(index, 1);
|
user.notifications.splice(index, 1);
|
||||||
@@ -129,7 +129,7 @@ api.seeNotification = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!notification) {
|
if (!notification) {
|
||||||
throw new NotFound(res.t('messageNotificationNotFound'));
|
throw new NotificationNotFound(req.language);
|
||||||
}
|
}
|
||||||
|
|
||||||
notification.seen = true;
|
notification.seen = true;
|
||||||
@@ -179,7 +179,7 @@ api.seeNotifications = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!notification) {
|
if (!notification) {
|
||||||
throw new NotFound(res.t('messageNotificationNotFound'));
|
throw new NotificationNotFound(req.language);
|
||||||
}
|
}
|
||||||
|
|
||||||
notification.seen = true;
|
notification.seen = true;
|
||||||
|
|||||||
@@ -41,6 +41,25 @@ export const BadRequest = common.errors.BadRequest;
|
|||||||
*/
|
*/
|
||||||
export const NotFound = common.errors.NotFound;
|
export const NotFound = common.errors.NotFound;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @apiDefine NotificationNotFound
|
||||||
|
* @apiError NotificationNotFound The notification was not found.
|
||||||
|
*
|
||||||
|
* @apiErrorExample Error-Response:
|
||||||
|
* HTTP/1.1 404 Not Found
|
||||||
|
* {
|
||||||
|
* "error": "NotificationNotFound",
|
||||||
|
* "message": "Notification not found."
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
export class NotificationNotFound extends NotFound {
|
||||||
|
constructor (language) {
|
||||||
|
super(common.i18n.t('messageNotificationNotFound', language));
|
||||||
|
this.name = this.constructor.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @apiDefine InternalServerError
|
* @apiDefine InternalServerError
|
||||||
* @apiError InternalServerError An unexpected error occurred.
|
* @apiError InternalServerError An unexpected error occurred.
|
||||||
|
|||||||
Reference in New Issue
Block a user