From d4d1e03479f948af7453a340878b3281e9d0faff Mon Sep 17 00:00:00 2001 From: Johann150 Date: Tue, 13 Dec 2022 20:35:46 +0100 Subject: [PATCH] server: fix errors for replies and state when note doesnt exist --- .../backend/src/server/api/endpoints/notes/replies.ts | 8 ++++++++ packages/backend/src/server/api/endpoints/notes/state.ts | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/server/api/endpoints/notes/replies.ts b/packages/backend/src/server/api/endpoints/notes/replies.ts index ab0018f58..b289e1147 100644 --- a/packages/backend/src/server/api/endpoints/notes/replies.ts +++ b/packages/backend/src/server/api/endpoints/notes/replies.ts @@ -4,6 +4,7 @@ import { makePaginationQuery } from '../../common/make-pagination-query.js'; import { generateVisibilityQuery } from '../../common/generate-visibility-query.js'; import { generateMutedUserQuery } from '../../common/generate-muted-user-query.js'; import { generateBlockedUserQuery } from '../../common/generate-block-query.js'; +import { ApiError } from '@/server/api/error.js'; export const meta = { tags: ['notes'], @@ -19,6 +20,8 @@ export const meta = { ref: 'Note', }, }, + + errors: ['NO_SUCH_NOTE'], } as const; export const paramDef = { @@ -34,6 +37,11 @@ export const paramDef = { // eslint-disable-next-line import/no-default-export export default define(meta, paramDef, async (ps, user) => { + const note = await getNote(ps.noteId, user).catch(err => { + if (err.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError('NO_SUCH_NOTE'); + throw err; + }); + const query = makePaginationQuery(Notes.createQueryBuilder('note'), ps.sinceId, ps.untilId) .andWhere('note.replyId = :replyId', { replyId: ps.noteId }) .innerJoinAndSelect('note.user', 'user') diff --git a/packages/backend/src/server/api/endpoints/notes/state.ts b/packages/backend/src/server/api/endpoints/notes/state.ts index 67579b2a6..610b1f497 100644 --- a/packages/backend/src/server/api/endpoints/notes/state.ts +++ b/packages/backend/src/server/api/endpoints/notes/state.ts @@ -1,6 +1,7 @@ import { NoteFavorites, Notes, NoteThreadMutings, NoteWatchings } from '@/models/index.js'; import { getNote } from '../../common/getters.js'; import define from '../../define.js'; +import { ApiError } from '@/server/api/error.js'; export const meta = { tags: ['notes'], @@ -25,6 +26,8 @@ export const meta = { }, }, }, + + errors: ['NO_SUCH_NOTE'], } as const; export const paramDef = { @@ -37,7 +40,10 @@ export const paramDef = { // eslint-disable-next-line import/no-default-export export default define(meta, paramDef, async (ps, user) => { - const note = await getNote(ps.noteId, user); + const note = await getNote(ps.noteId, user).catch(err => { + if (err.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError('NO_SUCH_NOTE'); + throw err; + }); const [favorite, watching, threadMuting] = await Promise.all([ NoteFavorites.count({