@othree.io/excuses
Version:
Excuses
31 lines • 1.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.InvalidDateError = void 0;
/**
* Custom Error class representing an invalid date format error.
*/
class InvalidDateError extends Error {
/**
* Creates a new InvalidDateError.
*
* @param {string} [format] - Expected date format that caused the error.
* @param {string} [value] - Date value that failed validation.
* @param {string} [message] - Optional custom error message.
*/
constructor(format, value, 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 = InvalidDateError.ERROR;
this.format = format;
this.value = value;
this.stack = new Error().stack;
if (format && value) {
this.message = `Invalid date ${value}. Required format: ${format}`;
}
}
}
exports.InvalidDateError = InvalidDateError;
/** Static error code to identify the error type. */
InvalidDateError.ERROR = 'InvalidDateError';
//# sourceMappingURL=invalid-date-error.js.map