all repos — kitten @ 6742b6ccdb8cfbedfbee82d9baa7c6da27190208

pkgs/router/src/errors.ts (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
import { InteractionReplyOptions } from "discord.js";

/**
 * throw this inside a middleware to intentionally halt execution without triggering
 * the error handler propagation chain.
 *
 * @example
 * ```ts
 * kitten.builder().use(async (interaction) => {
 * 	if (!isAuthorized) {
 * 		throw new HaltExecution({ content: "unauthorized.", flags: ["Ephemeral"] });
 * 	}
 * });
 * ```
 */
export class HaltExecution extends Error {
	constructor(public replyPayload?: string | InteractionReplyOptions) {
		super("execution halted by middleware.");
		this.name = "HaltExecution";
	}
}

/**
 * thrown when a generated custom ID exceeds discord's 100 character limit.
 *
 * @remarks
 * this usually happens when you store too much dynamic data in a component's options,
 * or if your component name is exceptionally long.
 *
 * kitten will warn you if you're close to the limit (subscribe to the `warn` event), but
 * this error will be thrown if you exceed it.
 */
export class CustomIdTooLong extends Error {
	constructor(componentName: string, length: number) {
		super(
			`custom ID for component "${componentName}" is too long (${length} characters). discord limits custom IDs to 100 characters.`,
		);
	}
}