feat: enhance booster role functionality with error handling and database migration
This commit is contained in:
@@ -120,4 +120,16 @@ describe("handleInteraction", () => {
|
||||
|
||||
expect(interaction.replies[0]).toEqual({ content: "Role name is already used", flags: MessageFlags.Ephemeral });
|
||||
});
|
||||
|
||||
test("hides failed query details from user replies", async () => {
|
||||
const interaction = new FakeInteraction("claim", { name: "VIP" });
|
||||
const service = new FakeService();
|
||||
service.claimRole = async () => {
|
||||
throw new Error("Failed query: insert into booster_roles params: secret");
|
||||
};
|
||||
|
||||
await handleInteraction(interaction, service, { isBoosting: async () => true });
|
||||
|
||||
expect(interaction.replies[0]).toEqual({ content: "Failed to save booster role. Any created role was cleaned up. Try again.", flags: MessageFlags.Ephemeral });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -95,10 +95,24 @@ export async function handleInteraction(
|
||||
throw new Error("Unknown booster-role subcommand");
|
||||
} catch (error) {
|
||||
logger.warn("Booster-role command failed", { error });
|
||||
await interaction.reply({ content: error instanceof Error ? error.message : "Command failed", flags: MessageFlags.Ephemeral });
|
||||
await interaction.reply({ content: toUserErrorMessage(error), flags: MessageFlags.Ephemeral });
|
||||
}
|
||||
}
|
||||
|
||||
function toUserErrorMessage(error: unknown): string {
|
||||
if (!(error instanceof Error)) return "Command failed";
|
||||
|
||||
if (error.message.includes("Failed query")) {
|
||||
return "Failed to save booster role. Any created role was cleaned up. Try again.";
|
||||
}
|
||||
|
||||
if (error.message.includes("Missing Permissions")) {
|
||||
return "Bot is missing permissions or role position to manage this role.";
|
||||
}
|
||||
|
||||
return error.message;
|
||||
}
|
||||
|
||||
function requireGuildId(guildId: string | null): string {
|
||||
if (!guildId) throw new Error("This command can only be used in a server");
|
||||
return guildId;
|
||||
|
||||
Reference in New Issue
Block a user