feat(domain): introduce typed error classes and replace fragile string-based error handling

This commit is contained in:
MythEclipse
2026-06-06 03:04:18 +07:00
parent e90a776a21
commit 03e2a28e97
5 changed files with 88 additions and 22 deletions
+45
View File
@@ -0,0 +1,45 @@
/**
* Base error for all Booster Role bot errors.
* Enables reliable error type checking via `instanceof` instead of fragile
* string matching on `error.message`.
*/
export class BoosterRoleError extends Error {
constructor(message: string) {
super(message);
this.name = "BoosterRoleError";
}
}
/**
* Input validation failures — user provided an invalid name, color, icon, etc.
* Safe to show the message directly to the end user.
*/
export class ValidationError extends BoosterRoleError {
constructor(message: string) {
super(message);
this.name = "ValidationError";
}
}
/**
* Resource not found — no stored role, no Discord role, etc.
* Safe to show the message directly to the end user.
*/
export class NotFoundError extends BoosterRoleError {
constructor(message: string) {
super(message);
this.name = "NotFoundError";
}
}
/**
* Permission / authorisation failures — user doesn't own the role, bot
* lacks permissions, position is unsafe, etc.
* Safe to show the message directly to the end user.
*/
export class PermissionError extends BoosterRoleError {
constructor(message: string) {
super(message);
this.name = "PermissionError";
}
}