Improve !ban error messages

This commit is contained in:
Dragory 2020-12-22 22:10:41 +02:00
parent f4fc46d6eb
commit fec2b49129
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
2 changed files with 12 additions and 3 deletions

View file

@ -98,7 +98,7 @@ export const BanCmd = modActionsCmd({
}); });
if (banResult.status === "failed") { if (banResult.status === "failed") {
sendErrorMessage(pluginData, msg.channel, `Failed to ban member`); sendErrorMessage(pluginData, msg.channel, `Failed to ban member: ${banResult.error}`);
return; return;
} }

View file

@ -8,13 +8,14 @@ import {
ucfirst, ucfirst,
UserNotificationResult, UserNotificationResult,
} from "../../../utils"; } from "../../../utils";
import { User } from "eris"; import { DiscordRESTError, User } from "eris";
import { renderTemplate } from "../../../templateFormatter"; import { renderTemplate } from "../../../templateFormatter";
import { getDefaultContactMethods } from "./getDefaultContactMethods"; import { getDefaultContactMethods } from "./getDefaultContactMethods";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { ignoreEvent } from "./ignoreEvent"; import { ignoreEvent } from "./ignoreEvent";
import { CasesPlugin } from "../../Cases/CasesPlugin"; import { CasesPlugin } from "../../Cases/CasesPlugin";
import { CaseTypes } from "../../../data/CaseTypes"; 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. * 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, reason != null ? encodeURIComponent(reason) : undefined,
); );
} catch (e) { } 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 { return {
status: "failed", status: "failed",
error: e.message, error: errorMessage,
}; };
} }