function newError(name) {
        function CustomError(message, properties) {
          if (!(this instanceof CustomError))
            return new CustomError(message, properties);

          // Error.call(this, message);
          // ^ just returns a new error instance because the ctor can be called as a function

          Object.defineProperty(this, "message", {
            get: function () {
              return message;
            },
          });

          /* istanbul ignore next */
          if (Error.captureStackTrace)
            // node
            Error.captureStackTrace(this, CustomError);
          else
            Object.defineProperty(this, "stack", {
              value: new Error().stack || "",
            });

          if (properties) merge(this, properties);
        }

        (CustomError.prototype = Object.create(Error.prototype)).constructor =
          CustomError;

        Object.defineProperty(CustomError.prototype, "name", {
          get: function () {
            return name;
          },
        });

        CustomError.prototype.toString = function toString() {
          return this.name + ": " + this.message;
        };

        return CustomError;
      }
/**
       * Creates a custom error constructor.
       * @memberof util
       * @param {string} name Error name
       * @returns {Constructor<Error>} Custom error constructor
       */
Creates a custom error constructor.
@memberof util
@param {string} name Error name
@returns {Constructor} Custom error constructor
Creates a custom error constructor . @memberof util @param { string } name Error name @returns { Constructor } Custom error constructor
function newError(name) {
        function CustomError(message, properties) {
          if (!(this instanceof CustomError))
            return new CustomError(message, properties);
          Object.defineProperty(this, "message", {
            get: function () {
              return message;
            },
          });
          if (Error.captureStackTrace)
            Error.captureStackTrace(this, CustomError);
          else
            Object.defineProperty(this, "stack", {
              value: new Error().stack || "",
            });
          if (properties) merge(this, properties);
        }
        (CustomError.prototype = Object.create(Error.prototype)).constructor =
          CustomError;
        Object.defineProperty(CustomError.prototype, "name", {
          get: function () {
            return name;
          },
        });
        CustomError.prototype.toString = function toString() {
          return this.name + ": " + this.message;
        };
        return CustomError;
      }
function newError ( name ) { function CustomError ( message , properties ) { if ( ! ( this instanceof CustomError ) ) return new CustomError ( message , properties ) ; Object . defineProperty ( this , "message" , { get : function ( ) { return message ; } , } ) ; if ( Error . captureStackTrace ) Error . captureStackTrace ( this , CustomError ) ; else Object . defineProperty ( this , "stack" , { value : new Error ( ) . stack || "" , } ) ; if ( properties ) merge ( this , properties ) ; } ( CustomError . prototype = Object . create ( Error . prototype ) ) . constructor = CustomError ; Object . defineProperty ( CustomError . prototype , "name" , { get : function ( ) { return name ; } , } ) ; CustomError . prototype . toString = function toString ( ) { return this . name + ": " + this . message ; } ; return CustomError ; }
Creates a custom error constructor.
Creates a custom error constructor .
// Error.call(this, message); // ^ just returns a new error instance because the ctor can be called as a function /* istanbul ignore next */ // node