fix
This commit is contained in:
parent
bb460a1785
commit
c3db55b5b6
2 changed files with 8 additions and 1 deletions
|
@ -15,6 +15,7 @@ import type { MiLocalUser } from '@/models/entities/User.js';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ClipService {
|
export class ClipService {
|
||||||
|
public static NoSuchNoteError = class extends Error {};
|
||||||
public static NoSuchClipError = class extends Error {};
|
public static NoSuchClipError = class extends Error {};
|
||||||
public static AlreadyAddedError = class extends Error {};
|
public static AlreadyAddedError = class extends Error {};
|
||||||
public static TooManyClipNotesError = class extends Error {};
|
public static TooManyClipNotesError = class extends Error {};
|
||||||
|
@ -118,10 +119,14 @@ export class ClipService {
|
||||||
noteId: noteId,
|
noteId: noteId,
|
||||||
clipId: clip.id,
|
clipId: clip.id,
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e: any) {
|
||||||
if (isDuplicateKeyValueError(e)) {
|
if (isDuplicateKeyValueError(e)) {
|
||||||
throw new ClipService.AlreadyAddedError();
|
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, {
|
this.clipsRepository.update(clip.id, {
|
||||||
|
|
|
@ -70,6 +70,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof ClipService.NoSuchClipError) {
|
if (e instanceof ClipService.NoSuchClipError) {
|
||||||
throw new ApiError(meta.errors.noSuchClip);
|
throw new ApiError(meta.errors.noSuchClip);
|
||||||
|
} else if (e instanceof ClipService.NoSuchNoteError) {
|
||||||
|
throw new ApiError(meta.errors.noSuchNote);
|
||||||
} else if (e instanceof ClipService.AlreadyAddedError) {
|
} else if (e instanceof ClipService.AlreadyAddedError) {
|
||||||
throw new ApiError(meta.errors.alreadyClipped);
|
throw new ApiError(meta.errors.alreadyClipped);
|
||||||
} else if (e instanceof ClipService.TooManyClipNotesError) {
|
} else if (e instanceof ClipService.TooManyClipNotesError) {
|
||||||
|
|
Loading…
Reference in a new issue