diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-10-04 13:53:48 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-10-04 13:53:48 +0900 |
| commit | fce7dc0f4e69053c7306289189b4fa4891f57339 (patch) | |
| tree | e18c90c403655fd52a137357499cd0de9a591bc1 /src/models/notification.ts | |
| parent | Improve default theme definition (dark) (diff) | |
| download | sharkey-fce7dc0f4e69053c7306289189b4fa4891f57339.tar.gz sharkey-fce7dc0f4e69053c7306289189b4fa4891f57339.tar.bz2 sharkey-fce7dc0f4e69053c7306289189b4fa4891f57339.zip | |
Improve error handling of pack function of notification
Diffstat (limited to 'src/models/notification.ts')
| -rw-r--r-- | src/models/notification.ts | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/models/notification.ts b/src/models/notification.ts index 835c89cd56..57be4bef10 100644 --- a/src/models/notification.ts +++ b/src/models/notification.ts @@ -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}`); |