fix: catch errors from packing with detail
Packing with detail can cause an error if the reply or renote are not visible to the user, even though the original note is visible to the user.
This commit is contained in:
parent
b630cd7eac
commit
3fe351df6d
3 changed files with 44 additions and 25 deletions
|
@ -39,6 +39,10 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
});
|
||||
|
||||
return await Notes.pack(note, user, {
|
||||
// FIXME: packing with detail may throw an error if the reply or renote is not visible (#8774)
|
||||
detail: true,
|
||||
}).catch(err => {
|
||||
if (err.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
|
|
|
@ -322,6 +322,8 @@ router.get('/notes/:note', async (ctx, next) => {
|
|||
});
|
||||
|
||||
if (note) {
|
||||
try {
|
||||
// FIXME: packing with detail may throw an error if the reply or renote is not visible (#8774)
|
||||
const _note = await Notes.pack(note);
|
||||
const profile = await UserProfiles.findOneByOrFail({ userId: note.userId });
|
||||
const meta = await fetchMeta();
|
||||
|
@ -339,6 +341,13 @@ router.get('/notes/:note', async (ctx, next) => {
|
|||
ctx.set('Cache-Control', 'public, max-age=15');
|
||||
|
||||
return;
|
||||
} catch (err) {
|
||||
if (err.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') {
|
||||
// note not visible to user
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await next();
|
||||
|
|
|
@ -640,6 +640,8 @@ async function createMentionedEvents(mentionedUsers: MinimumUser[], note: Note,
|
|||
continue;
|
||||
}
|
||||
|
||||
// note with "specified" visibility might not be visible to mentioned users
|
||||
try {
|
||||
const detailPackedNote = await Notes.pack(note, u, {
|
||||
detail: true,
|
||||
});
|
||||
|
@ -652,6 +654,10 @@ async function createMentionedEvents(mentionedUsers: MinimumUser[], note: Note,
|
|||
note: detailPackedNote,
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
if (err.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') continue;
|
||||
throw err;
|
||||
}
|
||||
|
||||
// Create notification
|
||||
nm.push(u.id, 'mention');
|
||||
|
|
Loading…
Reference in a new issue