Update ClipService.ts
This commit is contained in:
parent
053da10e94
commit
0183d24786
@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import * as Redis from 'ioredis';
|
import { QueryFailedError } from 'typeorm';
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
import type { ClipsRepository, MiNote, MiClip, ClipNotesRepository, NotesRepository } from '@/models/_.js';
|
import type { ClipsRepository, MiNote, MiClip, ClipNotesRepository, NotesRepository } from '@/models/_.js';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
@ -22,12 +22,6 @@ export class ClipService {
|
|||||||
public static TooManyClipsError = class extends Error {};
|
public static TooManyClipsError = class extends Error {};
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(DI.redis)
|
|
||||||
private redisClient: Redis.Redis,
|
|
||||||
|
|
||||||
@Inject(DI.redisForSub)
|
|
||||||
private redisForSub: Redis.Redis,
|
|
||||||
|
|
||||||
@Inject(DI.clipsRepository)
|
@Inject(DI.clipsRepository)
|
||||||
private clipsRepository: ClipsRepository,
|
private clipsRepository: ClipsRepository,
|
||||||
|
|
||||||
@ -119,12 +113,14 @@ export class ClipService {
|
|||||||
noteId: noteId,
|
noteId: noteId,
|
||||||
clipId: clip.id,
|
clipId: clip.id,
|
||||||
});
|
});
|
||||||
} catch (e: any) {
|
} catch (e: unknown) {
|
||||||
|
if (e instanceof QueryFailedError) {
|
||||||
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".')) {
|
} else if (e.driverError.detail.includes('is not present in table "note".')) {
|
||||||
throw new ClipService.NoSuchNoteError();
|
throw new ClipService.NoSuchNoteError();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user