UNPKG

@othree.io/excuses

Version:

Excuses

30 lines 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DuplicateError = void 0; /** * Custom Error class representing a duplication error, typically used when an attempt is made to create an entity that already exists. */ class DuplicateError extends Error { /** * Creates a new DuplicateError. * * @param {string} [id] - Optional identifier of the entity that is considered a duplicate. * @param {string} [type] - Optional type or category of the entity. * @param {string} [message] - Optional custom error message. */ constructor(id, type, message) { super(message); // https://github.com/Microsoft/TypeScript-wiki/blob/main/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work Object.setPrototypeOf(this, new.target.prototype); // restore prototype chain this.name = DuplicateError.ERROR; this.id = id; this.stack = new Error().stack; if (id && type) { this.message = `${type} with id: ${id} already exists`; } } } exports.DuplicateError = DuplicateError; /** Static error code to identify the error type. */ DuplicateError.ERROR = 'DuplicateError'; //# sourceMappingURL=duplicate-error.js.map