From c6192ac95a21590276e53ba2bb4f26af0026e2f6 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Tue, 24 May 2022 09:48:33 +0200 Subject: [PATCH] fix: handle exception in note favorites --- packages/backend/src/models/repositories/note-favorite.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/models/repositories/note-favorite.ts b/packages/backend/src/models/repositories/note-favorite.ts index 9bd97f988..1d5702053 100644 --- a/packages/backend/src/models/repositories/note-favorite.ts +++ b/packages/backend/src/models/repositories/note-favorite.ts @@ -14,6 +14,7 @@ export const NoteFavoriteRepository = db.getRepository(NoteFavorite).extend({ id: favorite.id, createdAt: favorite.createdAt.toISOString(), noteId: favorite.noteId, + // may throw error note: await Notes.pack(favorite.note || favorite.noteId, me), }; }, @@ -22,6 +23,7 @@ export const NoteFavoriteRepository = db.getRepository(NoteFavorite).extend({ favorites: any[], me: { id: User['id'] } ) { - return Promise.all(favorites.map(x => this.pack(x, me))); + return Promise.allSettled(favorites.map(x => this.pack(x, me))) + .then(promises => promises.flatMap(result => result.status === 'fulfilled' ? [result.value] : [])); }, });