Improve error handling of pack function of notification
This commit is contained in:
parent
35489ef5b7
commit
fce7dc0f4e
3 changed files with 15 additions and 3 deletions
|
@ -79,7 +79,7 @@ export const pack = (
|
||||||
|
|
||||||
// (データベースの不具合などで)投稿が見つからなかったら
|
// (データベースの不具合などで)投稿が見つからなかったら
|
||||||
if (_favorite.note == null) {
|
if (_favorite.note == null) {
|
||||||
console.warn(`favorite: note not found on database: ${_favorite.noteId}`);
|
console.warn(`in packaging favorite: note not found on database: ${_favorite.noteId}`);
|
||||||
return resolve(null);
|
return resolve(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,12 @@ export async function deleteNotification(notification: string | mongo.ObjectID |
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const packMany = async (
|
||||||
|
notifications: any[]
|
||||||
|
) => {
|
||||||
|
return (await Promise.all(notifications.map(n => pack(n)))).filter(x => x != null);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pack a notification for API response
|
* Pack a notification for API response
|
||||||
*/
|
*/
|
||||||
|
@ -123,6 +129,12 @@ export const pack = (notification: any) => new Promise<any>(async (resolve, reje
|
||||||
case 'poll_vote':
|
case 'poll_vote':
|
||||||
// Populate note
|
// Populate note
|
||||||
_notification.note = await packNote(_notification.noteId, me);
|
_notification.note = await packNote(_notification.noteId, me);
|
||||||
|
|
||||||
|
// (データベースの不具合などで)投稿が見つからなかったら
|
||||||
|
if (_notification.note == null) {
|
||||||
|
console.warn(`in packaging notification: note not found on database: ${_notification.noteId}`);
|
||||||
|
return resolve(null);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.error(`Unknown type: ${_notification.type}`);
|
console.error(`Unknown type: ${_notification.type}`);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import $ from 'cafy'; import ID from '../../../../misc/cafy-id';
|
import $ from 'cafy'; import ID from '../../../../misc/cafy-id';
|
||||||
import Notification from '../../../../models/notification';
|
import Notification from '../../../../models/notification';
|
||||||
import Mute from '../../../../models/mute';
|
import Mute from '../../../../models/mute';
|
||||||
import { pack } from '../../../../models/notification';
|
import { packMany } from '../../../../models/notification';
|
||||||
import { getFriendIds } from '../../common/get-friends';
|
import { getFriendIds } from '../../common/get-friends';
|
||||||
import read from '../../common/read-notification';
|
import read from '../../common/read-notification';
|
||||||
import { ILocalUser } from '../../../../models/user';
|
import { ILocalUser } from '../../../../models/user';
|
||||||
|
@ -83,7 +83,7 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||||
});
|
});
|
||||||
|
|
||||||
// Serialize
|
// Serialize
|
||||||
res(await Promise.all(notifications.map(notification => pack(notification))));
|
res(await packMany(notifications));
|
||||||
|
|
||||||
// Mark all as read
|
// Mark all as read
|
||||||
if (notifications.length > 0 && markAsRead) {
|
if (notifications.length > 0 && markAsRead) {
|
||||||
|
|
Loading…
Reference in a new issue