[mastodon-client] Fix error when liking the same status twice

This commit is contained in:
Laura Hausmann 2023-10-07 17:27:45 +02:00
parent 6bf6a71151
commit f36515a221
No known key found for this signature in database
GPG Key ID: D044E84C5BE01605
2 changed files with 6 additions and 2 deletions

View File

@ -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<Note> {
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);
}

View File

@ -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;