@avonjs/avonjs
Version:
A fluent Node.js API generator.
39 lines (38 loc) • 1.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
class Exception extends Error {
message;
constructor(message = 'Something went wrong.', ...args) {
super(message);
this.message = message;
}
/**
* Throw the Exception.
*/
static throw(message, ...args) {
//TODO: should fix this.
// biome-ignore lint/complexity/noThisInStatic: This is a static method.
throw new this(message, ...args);
}
/**
* Generate an Exception if the given condition is satisfied.
*/
static when(condition, message, ...args) {
if (condition) {
//TODO: should fix this.
// biome-ignore lint/complexity/noThisInStatic: This is a static method.
this.throw(message, ...args);
}
}
/**
* Generate an Exception if the given condition is not satisfied.
*/
static unless(condition, message, ...args) {
if (!condition) {
//TODO: should fix this.
// biome-ignore lint/complexity/noThisInStatic: This is a static method.
this.throw(message, ...args);
}
}
}
exports.default = Exception;