From f36515a221148b8538bb9d5d7d6a97be036c8d52 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Sat, 7 Oct 2023 17:27:45 +0200 Subject: [PATCH] [mastodon-client] Fix error when liking the same status twice --- packages/backend/src/server/api/mastodon/helpers/note.ts | 6 +++++- packages/backend/src/services/note/reaction/create.ts | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/server/api/mastodon/helpers/note.ts b/packages/backend/src/server/api/mastodon/helpers/note.ts index a2815bf11..17dc5f662 100644 --- a/packages/backend/src/server/api/mastodon/helpers/note.ts +++ b/packages/backend/src/server/api/mastodon/helpers/note.ts @@ -28,6 +28,7 @@ import { toArray } from "@/prelude/array.js"; import { MastoApiError } from "@/server/api/mastodon/middleware/catch-errors.js"; import { Cache } from "@/misc/cache.js"; import AsyncLock from "async-lock"; +import { IdentifiableError } from "@/misc/identifiable-error.js"; export class NoteHelpers { public static postIdempotencyCache = new Cache<{ status?: MastodonEntity.Status }>('postIdempotencyCache', 60 * 60); @@ -45,7 +46,10 @@ export class NoteHelpers { } public static async reactToNote(note: Note, user: ILocalUser, reaction: string): Promise { - await createReaction(user, note, reaction); + await createReaction(user, note, reaction).catch(e => { + if (e instanceof IdentifiableError && e.id == '51c42bb4-931a-456b-bff7-e5a8a70dd298') return; + throw e; + }); return getNote(note.id, user); } diff --git a/packages/backend/src/services/note/reaction/create.ts b/packages/backend/src/services/note/reaction/create.ts index 4cf1fd094..b72da417f 100644 --- a/packages/backend/src/services/note/reaction/create.ts +++ b/packages/backend/src/services/note/reaction/create.ts @@ -73,7 +73,7 @@ export default async ( await NoteReactions.insert(record); } else { // 同じリアクションがすでにされていたらエラー - throw new IdentifiableError("51c42bb4-931a-456b-bff7-e5a8a70dd298"); + throw new IdentifiableError("51c42bb4-931a-456b-bff7-e5a8a70dd298", "Reaction already exists"); } } else { throw e;