mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-21 02:06:43 +00:00
fix(discord): surface failed bulk reaction removals instead of false success (#90038)
This commit is contained in:
@@ -87,17 +87,13 @@ export async function removeOwnReactionsDiscord(
|
||||
if (identifiers.size === 0) {
|
||||
return { ok: true, removed: [] };
|
||||
}
|
||||
const removed: string[] = [];
|
||||
await Promise.allSettled(
|
||||
Array.from(identifiers, (identifier) => {
|
||||
removed.push(identifier);
|
||||
return deleteOwnMessageReaction(
|
||||
rest,
|
||||
channelId,
|
||||
messageId,
|
||||
normalizeReactionEmoji(identifier),
|
||||
);
|
||||
}),
|
||||
const removed = Array.from(identifiers);
|
||||
// Promise.all so a rejected delete propagates: allSettled would swallow the
|
||||
// failure and falsely report every identifier as removed.
|
||||
await Promise.all(
|
||||
removed.map((identifier) =>
|
||||
deleteOwnMessageReaction(rest, channelId, messageId, normalizeReactionEmoji(identifier)),
|
||||
),
|
||||
);
|
||||
return { ok: true, removed };
|
||||
}
|
||||
|
||||
@@ -861,6 +861,24 @@ describe("removeOwnReactionsDiscord", () => {
|
||||
Routes.channelMessageOwnReaction("chan1", "msg1", "party_blob%3A123"),
|
||||
);
|
||||
});
|
||||
|
||||
it("surfaces a failed deletion instead of reporting false success", async () => {
|
||||
const { rest, getMock, deleteMock } = makeDiscordRest();
|
||||
getMock.mockResolvedValue({
|
||||
reactions: [
|
||||
{ emoji: { name: "✅", id: null } },
|
||||
{ emoji: { name: "party_blob", id: "123" } },
|
||||
],
|
||||
});
|
||||
const apiError = new Error("Discord API 500");
|
||||
deleteMock.mockResolvedValueOnce(undefined);
|
||||
deleteMock.mockRejectedValueOnce(apiError);
|
||||
await expect(
|
||||
removeOwnReactionsDiscord("chan1", "msg1", { rest, token: "t", cfg: DISCORD_TEST_CFG }),
|
||||
).rejects.toThrow("Discord API 500");
|
||||
// Both deletions are still attempted; the rejection just propagates.
|
||||
expect(deleteMock).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("fetchReactionsDiscord", () => {
|
||||
|
||||
Reference in New Issue
Block a user