Improve error handling of pack function of notification
This commit is contained in:
parent
35489ef5b7
commit
fce7dc0f4e
|
@ -79,7 +79,7 @@ export const pack = (
|
|||
|
||||
// (データベースの不具合などで)投稿が見つからなかったら
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
@ -123,6 +129,12 @@ export const pack = (notification: any) => new Promise<any>(async (resolve, reje
|
|||
case 'poll_vote':
|
||||
// Populate note
|
||||
_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;
|
||||
default:
|
||||
console.error(`Unknown type: ${_notification.type}`);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import $ from 'cafy'; import ID from '../../../../misc/cafy-id';
|
||||
import Notification from '../../../../models/notification';
|
||||
import Mute from '../../../../models/mute';
|
||||
import { pack } from '../../../../models/notification';
|
||||
import { packMany } from '../../../../models/notification';
|
||||
import { getFriendIds } from '../../common/get-friends';
|
||||
import read from '../../common/read-notification';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
|
@ -83,7 +83,7 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
|||
});
|
||||
|
||||
// Serialize
|
||||
res(await Promise.all(notifications.map(notification => pack(notification))));
|
||||
res(await packMany(notifications));
|
||||
|
||||
// Mark all as read
|
||||
if (notifications.length > 0 && markAsRead) {
|
||||
|
|
Loading…
Reference in New Issue