From 6f32efd8985be64e50b7fdcbbab38bb23061989a Mon Sep 17 00:00:00 2001 From: s1idewhist1e Date: Sun, 30 Apr 2023 22:03:17 -0700 Subject: [PATCH] Wrap note fetching in a try/catch --- packages/backend/src/server/web/index.ts | 43 +++++++++++++----------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/packages/backend/src/server/web/index.ts b/packages/backend/src/server/web/index.ts index 642a17d578..270026dcc1 100644 --- a/packages/backend/src/server/web/index.ts +++ b/packages/backend/src/server/web/index.ts @@ -399,28 +399,31 @@ router.get("/notes/:note", async (ctx, next) => { visibility: In(["public", "home"]), }); - if (note) { - const _note = await Notes.pack(note); - const profile = await UserProfiles.findOneByOrFail({ userId: note.userId }); - const meta = await fetchMeta(); - await ctx.render("note", { - note: _note, - profile, - avatarUrl: await Users.getAvatarUrl( - await Users.findOneByOrFail({ id: note.userId }), - ), - // TODO: Let locale changeable by instance setting - summary: getNoteSummary(_note), - instanceName: meta.name || "Calckey", - icon: meta.iconUrl, - privateMode: meta.privateMode, - themeColor: meta.themeColor, - }); + try { + if (note) { + const _note = await Notes.pack(note); + + const profile = await UserProfiles.findOneByOrFail({ userId: note.userId }); + const meta = await fetchMeta(); + await ctx.render("note", { + note: _note, + profile, + avatarUrl: await Users.getAvatarUrl( + await Users.findOneByOrFail({ id: note.userId }), + ), + // TODO: Let locale changeable by instance setting + summary: getNoteSummary(_note), + instanceName: meta.name || "Calckey", + icon: meta.iconUrl, + privateMode: meta.privateMode, + themeColor: meta.themeColor, + }); - ctx.set("Cache-Control", "public, max-age=15"); + ctx.set("Cache-Control", "public, max-age=15"); - return; - } + return; + } + } catch {} await next(); });