From fec2b491292410adaee613387bc3463d06d84e9b Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Tue, 22 Dec 2020 22:10:41 +0200 Subject: [PATCH] Improve !ban error messages --- backend/src/plugins/ModActions/commands/BanCmd.ts | 2 +- .../src/plugins/ModActions/functions/banUserId.ts | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/backend/src/plugins/ModActions/commands/BanCmd.ts b/backend/src/plugins/ModActions/commands/BanCmd.ts index 1e3b9d79..cf8ac261 100644 --- a/backend/src/plugins/ModActions/commands/BanCmd.ts +++ b/backend/src/plugins/ModActions/commands/BanCmd.ts @@ -98,7 +98,7 @@ export const BanCmd = modActionsCmd({ }); if (banResult.status === "failed") { - sendErrorMessage(pluginData, msg.channel, `Failed to ban member`); + sendErrorMessage(pluginData, msg.channel, `Failed to ban member: ${banResult.error}`); return; } diff --git a/backend/src/plugins/ModActions/functions/banUserId.ts b/backend/src/plugins/ModActions/functions/banUserId.ts index 30661c75..74c0357b 100644 --- a/backend/src/plugins/ModActions/functions/banUserId.ts +++ b/backend/src/plugins/ModActions/functions/banUserId.ts @@ -8,13 +8,14 @@ import { ucfirst, UserNotificationResult, } from "../../../utils"; -import { User } from "eris"; +import { DiscordRESTError, User } from "eris"; import { renderTemplate } from "../../../templateFormatter"; import { getDefaultContactMethods } from "./getDefaultContactMethods"; import { LogType } from "../../../data/LogType"; import { ignoreEvent } from "./ignoreEvent"; import { CasesPlugin } from "../../Cases/CasesPlugin"; import { CaseTypes } from "../../../data/CaseTypes"; +import { logger } from "../../../logger"; /** * Ban the specified user id, whether or not they're actually on the server at the time. Generates a case. @@ -69,9 +70,17 @@ export async function banUserId( reason != null ? encodeURIComponent(reason) : undefined, ); } catch (e) { + let errorMessage; + if (e instanceof DiscordRESTError) { + errorMessage = `API error ${e.code}: ${e.message}`; + } else { + logger.warn(`Error applying ban to ${userId}: ${e}`); + errorMessage = "Unknown error"; + } + return { status: "failed", - error: e.message, + error: errorMessage, }; }