Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
syuilo committed Sep 20, 2023
1 parent bb460a1 commit c3db55b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/backend/src/core/ClipService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type { MiLocalUser } from '@/models/entities/User.js';

@Injectable()
export class ClipService {
public static NoSuchNoteError = class extends Error {};
public static NoSuchClipError = class extends Error {};
public static AlreadyAddedError = class extends Error {};
public static TooManyClipNotesError = class extends Error {};
Expand Down Expand Up @@ -118,10 +119,14 @@ export class ClipService {
noteId: noteId,
clipId: clip.id,
});
} catch (e) {
} catch (e: any) {
if (isDuplicateKeyValueError(e)) {
throw new ClipService.AlreadyAddedError();
} else if (e.detail.includes('is not present in table "note".')) {
throw new ClipService.NoSuchNoteError();
}

throw e;
}

this.clipsRepository.update(clip.id, {
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/server/api/endpoints/clips/add-note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // 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);
} else if (e instanceof ClipService.AlreadyAddedError) {
throw new ApiError(meta.errors.alreadyClipped);
} else if (e instanceof ClipService.TooManyClipNotesError) {
Expand Down

0 comments on commit c3db55b

Please sign in to comment.