43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
/**
|
|
* Error category enum for classifying bot errors.
|
|
*/
|
|
export enum ErrorCategory {
|
|
USER_INPUT = 'USER_INPUT',
|
|
PERMISSION = 'PERMISSION',
|
|
BOT_INTERNAL = 'BOT_INTERNAL',
|
|
DISCORD_API = 'DISCORD_API',
|
|
}
|
|
|
|
/**
|
|
* Custom error class for Kord bot.
|
|
* Uses i18n message keys instead of hardcoded strings.
|
|
* The actual translated message is resolved at report time by ErrorReporter.
|
|
*/
|
|
export class BotError extends Error {
|
|
/** Error code for internal tracking (e.g. 'E2001') — NOT shown to users */
|
|
public readonly code: string;
|
|
|
|
/** Error category for determining response styling */
|
|
public readonly category: ErrorCategory;
|
|
|
|
/** i18n key prefix for looking up translations (e.g. 'errors.E2001') */
|
|
public readonly messageKey: string;
|
|
|
|
/** Original error that caused this BotError */
|
|
public readonly cause?: Error;
|
|
|
|
constructor(options: {
|
|
code: string;
|
|
category: ErrorCategory;
|
|
messageKey: string;
|
|
cause?: Error;
|
|
}) {
|
|
super(`[${options.code}] ${options.messageKey}`);
|
|
this.name = 'BotError';
|
|
this.code = options.code;
|
|
this.category = options.category;
|
|
this.messageKey = options.messageKey;
|
|
this.cause = options.cause;
|
|
}
|
|
}
|