Wrap note fetching in a try/catch

This commit is contained in:
s1idewhist1e 2023-04-30 22:03:17 -07:00
parent 34a6e1caa4
commit 6f32efd898
No known key found for this signature in database
GPG Key ID: 75E83831162775BB
1 changed files with 23 additions and 20 deletions

View File

@ -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();
});