From fa13b815ef8412db592e6cb4926cf2dde32f1c0b Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 20 Sep 2023 11:43:33 +0900 Subject: [PATCH] fix: provide NoSuchNoteError error --- packages/backend/src/core/ClipService.ts | 6 ++++++ .../backend/src/server/api/endpoints/clips/remove-note.ts | 2 ++ 2 files changed, 8 insertions(+) diff --git a/packages/backend/src/core/ClipService.ts b/packages/backend/src/core/ClipService.ts index 5dfb3b33a6..3d9982e80f 100644 --- a/packages/backend/src/core/ClipService.ts +++ b/packages/backend/src/core/ClipService.ts @@ -143,6 +143,12 @@ export class ClipService { throw new ClipService.NoSuchClipError(); } + const note = await this.notesRepository.findOneBy({ id: noteId }); + + if (note == null) { + throw new ClipService.NoSuchNoteError(); + } + await this.clipNotesRepository.delete({ noteId: noteId, clipId: clip.id, diff --git a/packages/backend/src/server/api/endpoints/clips/remove-note.ts b/packages/backend/src/server/api/endpoints/clips/remove-note.ts index d84a57cac0..7b153cb555 100644 --- a/packages/backend/src/server/api/endpoints/clips/remove-note.ts +++ b/packages/backend/src/server/api/endpoints/clips/remove-note.ts @@ -52,6 +52,8 @@ export default class extends Endpoint { // eslint- } catch (e) { if (e instanceof ClipService.NoSuchClipError) { throw new ApiError(meta.errors.noSuchClip); + } else if (e instanceof ClipService.NoSuchNoteError) { + throw new ApiError(meta.errors.noSuchNote); } throw e; }