From 0183d24786b0821af3be136acdc10503ed1019f4 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 20 Sep 2023 11:36:39 +0900 Subject: [PATCH] Update ClipService.ts --- packages/backend/src/core/ClipService.ts | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/packages/backend/src/core/ClipService.ts b/packages/backend/src/core/ClipService.ts index ff3a2b48e5..5dfb3b33a6 100644 --- a/packages/backend/src/core/ClipService.ts +++ b/packages/backend/src/core/ClipService.ts @@ -4,7 +4,7 @@ */ import { Inject, Injectable } from '@nestjs/common'; -import * as Redis from 'ioredis'; +import { QueryFailedError } from 'typeorm'; import { DI } from '@/di-symbols.js'; import type { ClipsRepository, MiNote, MiClip, ClipNotesRepository, NotesRepository } from '@/models/_.js'; import { bindThis } from '@/decorators.js'; @@ -22,12 +22,6 @@ export class ClipService { public static TooManyClipsError = class extends Error {}; constructor( - @Inject(DI.redis) - private redisClient: Redis.Redis, - - @Inject(DI.redisForSub) - private redisForSub: Redis.Redis, - @Inject(DI.clipsRepository) private clipsRepository: ClipsRepository, @@ -119,11 +113,13 @@ export class ClipService { noteId: noteId, clipId: clip.id, }); - } 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(); + } catch (e: unknown) { + if (e instanceof QueryFailedError) { + if (isDuplicateKeyValueError(e)) { + throw new ClipService.AlreadyAddedError(); + } else if (e.driverError.detail.includes('is not present in table "note".')) { + throw new ClipService.NoSuchNoteError(); + } } throw e;