Содержание

CustomError класс

CommonJS CJS

CustomError.js
function CustomError() {
    const instance = Reflect.construct(Error, arguments);
    Reflect.setPrototypeOf(instance, Reflect.getPrototypeOf(this));
    return instance;
}
CustomError.prototype = Object.create(Error.prototype, {
    constructor: {
        value: Error,
        enumerable: false,
        writable: true,
        configurable: true
    }
});
Reflect.setPrototypeOf(CustomError, Error);
module.exports = CustomError;

EcmaScriptModule ESM

CustomError.js
class CustomError extends Error {
  constructor(...args) {
    super(args)
  }
}
CustomError.constructor.name = 'CustomError'
export default CustomError